New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #4387: problem with usage of third-party Check libraries and ch… #4389
Conversation
Should we change the map from
Change the POM for the |
Now I think that we should not use the checkstyle's class. Before excute this line: https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java#L146, we have already search the name in the hard coded map, that means we are not able to generate a checkstyle's class already.
IMO it could not solve the problem. When users write a "FooCheck" in the config xml, and there are more than one check named "FooCheck", we don't know which one users exactly want. IMO, trying to instantiate them one by one and return the first one successful is not a good solution. |
@Luolc Yes, I agree. For our checks we should drop them from 3rd party checks. We should identify our checks as the ones in the field |
@Luolc , @rnveach , we will never guess what used meant by his config. All we need is to throw exception as we do now, but clearly define what we do not like: Internally in maps we should keep know about all classes. |
@romani |
Codecov Report
@@ Coverage Diff @@
## master #4389 +/- ##
======================================
Coverage 100% 100%
======================================
Files 285 285
Lines 15292 15310 +18
Branches 3477 3480 +3
======================================
+ Hits 15292 15310 +18
Continue to review full report at Codecov.
|
current fix can not be merged as it will not allow to use non-standard Check as override for standard, that probably all users did.
We should not care about any madness in classpath of user till it make problem to us.
Yes, when we are not sure, the whole responsibility in user. |
@rnveach
The filter could drop the standard checkstyle's check(by checking whether I will move on to the ambiguous name problem after I confirm whether the filter way could work for the sevntu issue. BTW, would I fix the ambiguous name problem in this PR as well or split a new issue? |
@Luolc ,
please share all changes with us, to help you, looks like problem is in tiny nuance. If share your sources , I can you code.
You can not reproduce problem or check fix ? All CIs reproduced it.
filter fix is not acceptable, please provide fix with exception for ambiguous name in this PR. |
Most likely your install wasn't successful as long as you saved your changes to that
This is the print out:
@romani As long as they use a different package for their check, they can use the non-standard check by using the fully qualified path in the configuration. We should always default to our checks first if just the check name is given IMO. If they use the EXACT same package and class name as our checks, we cannot guarantee which one the java classloader will use. |
I removed all files in
I can reproduce the problem. I mean I could not check my fix before, now the SNAPSHOT works.
Sure. With the current changes(the filter), So there are some strategies now:
I think if there are two third-party checks with same name, we should throw exception obviously. @romani @rnveach , I would work on the fix once you confirm to use which strategy :D |
I vote for "3)" and only when we try to instantiate Module (unclear name is on config) |
@romani |
yes, for all conflicting names ONLY.
There are bunch of users, you can find them even on github. |
Got it. So (3) wins. Last thing to confirm, should I also change the sevntu's config xml in this PR? If answer is yes, in one commit or separate commits? |
Most likely yes. Sevntu config is used in our other projects, so it has to stand up to this fix and not cause issues. See https://github.com/checkstyle/sonar-checkstyle/blob/master/checkstyle-sonar-plugin/pom.xml#L201 .
2 is fine. Edit: sorry for the multiple posts. |
…ies and checkstyle 7.8
@@ -467,7 +467,7 @@ | |||
<dependency> | |||
<groupId>com.puppycrawl.tools</groupId> | |||
<artifactId>checkstyle</artifactId> | |||
<version>7.8</version> | |||
<version>7.9-SNAPSHOT</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With version 7.8, this fix won't affect the maven checkstyle check task. CI would still fail. So I change it to 7.9-SNAPSHOT. Is it OK? Why did we use stable version but not current SNAPSHOT version before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think maven would work with dependency that defines itself if said dependency hasn't been installed yet as it gets all dependencies from the maven cache folder.
Can someone confirm it isn't using the previously installed SNAPSHOT version? (I believe this is what is happening)
If this does work as intended than #4403 isn't needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it does work. I can run the checkstyle phase without the dependency installed.
If a dependency is already installed, it still seems to use the current project and not the installed one.
I'm still looking if maven documents this behavior somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we use stable version but not current SNAPSHOT version before?
Maven release plugin is failing if any snapshot version is found, as release version have to be stable and based on strict versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smth to confirm:
|
Option 3 is only if simple module name is used and it exists in 3rd party and checkstyle.
Hardcoded map isn't meaningless. Here is the new order of operation as I have understood the discussion:
1-3 should only be done if module is simple name (no period).
With option 3, we should get exception with sevntu config as it is, since it uses simple names, once changed, it shouldn't fail. |
to my mind problem is in loading of Checks from class path.
so we cheated on name and it is now a problem. In code above there is no filter for known standard Check classes by fully qualified names. But there will be still possibility to have name conflicts in few thirdparty jars. So lets create separate issue on this and process it separately, as we need to fix our CIs(builds) ASAP. So current fix branch we be moved to next PR/issue. And we need to back to one of first solution with filtering. @Luolc , @rnveach are you agree to make fix in few steps/PRs ? |
@romani I agree, just to re-confirm what needs to be done:
|
yes, just "remove 'ambiguous name' exception" will be copy all changes to another branch on Luolc repo, as we will continue discussion . |
I am closing this PR, as it need to be recreated with reference to new issue. |
#4387
@romani
https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java#L202
The direct cause is that we have duplicate keys(the class simple name) in this stream.
I guess the reason is we have some classes that have the same simple name in both checkstyle project and sevntu.checkstyle project.
We could see
HideUtilityClassConstructorCheck
in the log, and there are https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/design/HideUtilityClassConstructorCheck.java and https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/HideUtilityClassConstructorCheck.java.I am not sure which class should I use here. More specifically, to use checkstyle's HideUtilityClassConstructorCheck or sevntu.checkstyle's HideUtilityClassConstructorCheck? (same question with other classes with same name) Currently I just choose the new one in the stream.
I don't know how to reproduce the bug in IDE currently. So I was not able to use a debug mode to check the
packages
field when the bug occurs.