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

PackageObjectFactory hides real exception #3778

Closed
rnveach opened this Issue Jan 30, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@rnveach
Member

rnveach commented Jan 30, 2017

While upgrading backport to 7.5, running Checkstyle on the project resulted in AtclauseOrderCheck to not be able to be instantiated.

com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Unable to instantiate 'AtclauseOrder' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.blocks.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.coding.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.design.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.header.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.imports.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.indentation.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.javadoc.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.metrics.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.modifier.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.naming.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.regexp.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.sizes.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.whitespace.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.AtclauseOrder, com.puppycrawl.tools.checkstyle.filefilters.AtclauseOrder, com.puppycrawl.tools.checkstyle.filters.AtclauseOrder, com.puppycrawl.tools.checkstyle.AtclauseOrder, AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.annotation.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.blocks.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.coding.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.design.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.header.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.imports.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.indentation.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.javadoc.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.metrics.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.modifier.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.naming.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.regexp.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.sizes.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.whitespace.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.filefilters.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.filters.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.AtclauseOrderCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage http://checkstyle.sourceforge.net/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
	at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:455)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)
	at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:423)
	at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:361)
	at com.puppycrawl.tools.checkstyle.Main.main(Main.java:176)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'AtclauseOrder' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.blocks.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.coding.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.design.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.header.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.imports.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.indentation.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.javadoc.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.metrics.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.modifier.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.naming.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.regexp.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.sizes.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.whitespace.AtclauseOrder, com.puppycrawl.tools.checkstyle.checks.AtclauseOrder, com.puppycrawl.tools.checkstyle.filefilters.AtclauseOrder, com.puppycrawl.tools.checkstyle.filters.AtclauseOrder, com.puppycrawl.tools.checkstyle.AtclauseOrder, AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.annotation.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.blocks.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.coding.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.design.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.header.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.imports.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.indentation.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.javadoc.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.metrics.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.modifier.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.naming.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.regexp.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.sizes.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.whitespace.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.checks.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.filefilters.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.filters.AtclauseOrderCheck, com.puppycrawl.tools.checkstyle.AtclauseOrderCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage http://checkstyle.sourceforge.net/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
	at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:139)
	at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:152)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)
	at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:450)
	... 4 more
Checkstyle ends with 1 errors.

There was no good reason for the problem given in the exception log so I had to dig into the problem manually. When debugging the problem, I found that the module was found in the Map and was located using Class.for but it failed to instantiate the check. No exception was being printed or reported because it was being ignored via

.
When adding a printStackTrace the reason for the problem was shown.

java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createObject(PackageObjectFactory.java:223)
	at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createObjectFromMap(PackageObjectFactory.java:160)
	at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:124)
	at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:152)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)
	at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:450)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)
	at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:423)
	at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:361)
	at com.puppycrawl.tools.checkstyle.Main.main(Main.java:176)
Caused by: java.lang.UnsupportedClassVersionError: org/antlr/v4/runtime/misc/ParseCancellationException : Unsupported major.minor version 51.0

Reason for exception was antlr upgraded to Java 7 in 4.6 .

I think this error should have been reported in the console. The original reason for ignoring the exception was because Class.for could fail while we search for the module. In this case, it wasn't failing to find it.
IMO, we should report any exception after Class.for succeeds when we fail to work with the constructor or instantiating. We found the class, no other work or searching we do will get it to instantiate correctly.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jan 30, 2017

Member

IMO, we should report any exception after Class.for

agree, the place for logic that is based on exception should be as narrow as possible. Brute force search is our old design problem. Ignorance of exceptions should only for code/lines that support brute force search of module in classpath.

Member

romani commented Jan 30, 2017

IMO, we should report any exception after Class.for

agree, the place for logic that is based on exception should be as narrow as possible. Brute force search is our old design problem. Ignorance of exceptions should only for code/lines that support brute force search of module in classpath.

@romani romani added the approved label Jan 30, 2017

rnveach added a commit to rnveach/checkstyle that referenced this issue Jan 30, 2017

rnveach added a commit to rnveach/checkstyle that referenced this issue Jan 31, 2017

rnveach added a commit to rnveach/checkstyle that referenced this issue Jan 31, 2017

romani added a commit that referenced this issue Feb 1, 2017

@romani romani added the bug label Feb 1, 2017

@romani romani added this to the 7.6 milestone Feb 1, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Feb 1, 2017

Member

fix is merged.

Member

romani commented Feb 1, 2017

fix is merged.

@romani romani closed this Feb 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment