After upgrading to Eclipse Oxygen and eclipse-cs 8.0.0, my custom checks can no longer be instantiated by Checkstyle. I was able to reproduce this error using the SevNTU plugin as well (stack trace below). Any ideas?
Checkstyle-Plugin: cannot initialize module TreeWalker - Unable to instantiate 'ForbidAnnotationCheck' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotationForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.blocksForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.codingForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.designForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.headerForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.importsForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.indentationForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.javadocForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.metricsForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.modifierForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.namingForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.regexpForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.sizesForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checks.whitespaceForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.checksForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.filefiltersForbidAnnotationCheck, com.puppycrawl.tools.checkstyle.filtersForbidAnnotationCheck, com.puppycrawl.tools.checkstyleForbidAnnotationCheck, com.github.sevntu.checkstyle.checks.annotationForbidAnnotationCheck, com.github.sevntu.checkstyle.checks.codingForbidAnnotationCheck, com.github.sevntu.checkstyle.checks.designForbidAnnotationCheck, com.github.sevntu.checkstyle.checks.namingForbidAnnotationCheck, com.github.sevntu.checkstyle.checks.sizesForbidAnnotationCheck, com.github.sevntu.checkstyle.checksForbidAnnotationCheck, com.github.sevntu.checkstyle.ForbidAnnotationCheck, ForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.annotationForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.blocksForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.codingForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.designForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.headerForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.importsForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.indentationForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.javadocForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.metricsForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.modifierForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.namingForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.regexpForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.sizesForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checks.whitespaceForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.checksForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.filefiltersForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyle.filtersForbidAnnotationCheckCheck, com.puppycrawl.tools.checkstyleForbidAnnotationCheckCheck, com.github.sevntu.checkstyle.checks.annotationForbidAnnotationCheckCheck, com.github.sevntu.checkstyle.checks.codingForbidAnnotationCheckCheck, com.github.sevntu.checkstyle.checks.designForbidAnnotationCheckCheck, com.github.sevntu.checkstyle.checks.namingForbidAnnotationCheckCheck, com.github.sevntu.checkstyle.checks.sizesForbidAnnotationCheckCheck, com.github.sevntu.checkstyle.checksForbidAnnotationCheckCheck, com.github.sevntu.checkstyle.ForbidAnnotationCheckCheck. 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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
!ENTRY net.sf.eclipsecs.core 4 0 2017-07-31 12:53:19.062!MESSAGE Checkstyle-Plugin: cannot initialize module TreeWalker - Unable to instantiate 'Jsr305Annotations' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotationJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.blocksJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.codingJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.designJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.headerJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.importsJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.indentationJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.javadocJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.metricsJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.modifierJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.namingJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.regexpJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.sizesJsr305Annotations, com.puppycrawl.tools.checkstyle.checks.whitespaceJsr305Annotations, com.puppycrawl.tools.checkstyle.checksJsr305Annotations, com.puppycrawl.tools.checkstyle.filefiltersJsr305Annotations, com.puppycrawl.tools.checkstyle.filtersJsr305Annotations, com.puppycrawl.tools.checkstyle.Jsr305Annotations, Jsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.annotationJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.blocksJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.codingJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.designJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.headerJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.importsJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.indentationJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.javadocJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.metricsJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.modifierJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.namingJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.regexpJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.sizesJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checks.whitespaceJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.checksJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.filefiltersJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.filtersJsr305AnnotationsCheck, com.puppycrawl.tools.checkstyle.Jsr305AnnotationsCheck. 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.!STACK 0com.puppycrawl.tools.checkstyle.api.CheckstyleException:cannotinitializemoduleTreeWalker-Unabletoinstantiate'Jsr305Annotations'class,itisalsonotpossibletoinstantiateitascom.puppycrawl.tools.checkstyle.checks.annotationJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.blocksJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.codingJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.designJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.headerJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.importsJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.indentationJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.javadocJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.metricsJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.modifierJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.namingJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.regexpJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.sizesJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.whitespaceJsr305Annotations,com.puppycrawl.tools.checkstyle.checksJsr305Annotations,com.puppycrawl.tools.checkstyle.filefiltersJsr305Annotations,com.puppycrawl.tools.checkstyle.filtersJsr305Annotations,com.puppycrawl.tools.checkstyle.Jsr305Annotations,Jsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.annotationJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.blocksJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.codingJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.designJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.headerJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.importsJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.indentationJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.javadocJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.metricsJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.modifierJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.namingJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.regexpJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.sizesJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.whitespaceJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checksJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.filefiltersJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.filtersJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.Jsr305AnnotationsCheck.Pleaserecheckthatclassnameisspecifiedascanonicalnameorreadhowtoconfigureshortnameusagehttp://checkstyle.sourceforge.net/config.html#Packages.PleasealsorecheckthatprovidedClassLoadertoCheckerisconfiguredcorrectly.atcom.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:457)atcom.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)atnet.sf.eclipsecs.core.builder.CheckerFactory.createCheckerInternal(CheckerFactory.java:290)atnet.sf.eclipsecs.core.builder.CheckerFactory.createChecker(CheckerFactory.java:128)atnet.sf.eclipsecs.core.builder.Auditor.runAudit(Auditor.java:141)atnet.sf.eclipsecs.core.builder.CheckstyleBuilder.handleBuildSelection(CheckstyleBuilder.java:301)atnet.sf.eclipsecs.core.jobs.RunCheckstyleOnFilesJob.runInWorkspace(RunCheckstyleOnFilesJob.java:119)atorg.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)atorg.eclipse.core.internal.jobs.Worker.run(Worker.java:55)Causedby:com.puppycrawl.tools.checkstyle.api.CheckstyleException:Unabletoinstantiate'Jsr305Annotations'class,itisalsonotpossibletoinstantiateitascom.puppycrawl.tools.checkstyle.checks.annotationJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.blocksJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.codingJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.designJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.headerJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.importsJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.indentationJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.javadocJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.metricsJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.modifierJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.namingJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.regexpJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.sizesJsr305Annotations,com.puppycrawl.tools.checkstyle.checks.whitespaceJsr305Annotations,com.puppycrawl.tools.checkstyle.checksJsr305Annotations,com.puppycrawl.tools.checkstyle.filefiltersJsr305Annotations,com.puppycrawl.tools.checkstyle.filtersJsr305Annotations,com.puppycrawl.tools.checkstyle.Jsr305Annotations,Jsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.annotationJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.blocksJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.codingJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.designJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.headerJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.importsJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.indentationJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.javadocJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.metricsJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.modifierJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.namingJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.regexpJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.sizesJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checks.whitespaceJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.checksJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.filefiltersJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.filtersJsr305AnnotationsCheck,com.puppycrawl.tools.checkstyle.Jsr305AnnotationsCheck.Pleaserecheckthatclassnameisspecifiedascanonicalnameorreadhowtoconfigureshortnameusagehttp://checkstyle.sourceforge.net/config.html#Packages.PleasealsorecheckthatprovidedClassLoadertoCheckerisconfiguredcorrectly.atcom.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:184)atcom.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:153)atcom.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)atcom.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:452)... 8 more
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I assume this to be related to a Checkstyle-internal change concerning the handling of checkstyle_packages.xml files.
Please note in the Exception message that there is a dot missing between the package and class name which Checkstyle core constructs from the checkstyle_packages.xml and the check name from the loaded configuration, e.g. com.puppycrawl.tools.checkstyle.checks.annotationJsr305Annotations
Please check with the Checkstyle core project where this change comes from. If my theory holds true, then custom checks will also not work with Checkstyle Ant/Maven tasks using Checkstyle 8.0.
Regards,
Lars
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've included tests against checkstyle 8 which are working well: https://travis-ci.org/bjrke/JSR305CheckstylePlugin
When I upgrade the gradle build of our big project to Checkstyle 8.0 it is working with a dev version of the plugin, too.
But I'll investigate the missing dot, perhaps there is a strange configuration issue.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think the problem with loading is an eclipse-cs problem. Because as I already mentioned, I've upgraded the inheritance in https://github.com/bjrke/JSR305CheckstylePlugin/commit/e5fdf3c1340dbeb9bd5db79b9ad5448418b8dbb4 and I've tests against all known working checkstyle versions, including 8.0 and 8.1.
But I didn't released yet since eclipse-cs is not working.
To do more tests I need to setup a new environment because I need my eclipse for daily work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I made some changes (i.e. adding plugin.xml) in the jar and now I get my package (with correct dots) in the error message, but it is still not loaded. So the checkstyle-metadata.xml is loading correct. Any ideas?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My custom check is also displayed with the correct dots in the error message but still is not loaded. Perhaps the incorrect dots in the error message was a red herring and not related to the class loading problem?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, indeed the error message was misleading.
I did half an hour of debugging today and from what I can deduce there is something off with the classpath scanning for check class, introduced with https://github.com/checkstyle/checkstyle/issues/3607
However, I couldn't get to the bottom of this just yet - will need more time
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thank you for your effort debugging this issue!
do you think eclipse-cs could workaround this issue or do we have to wait for a solution from the checkstyle maintainers?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unfortunately I don't think a workaround in eclipse-cs is feasible (or even possible).
In my eyes the current classpath scanning implementation offers no practical benefit over the long standing previous implementation while adding serious drawbacks. I hope the points brought forward are sufficient to convince the Checkstyle team to revert this change.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a plugin that extends Checkstyle with custom checks as described here:
http://eclipse-cs.sourceforge.net/#!/custom-checks
After upgrading to Eclipse Oxygen and eclipse-cs 8.0.0, my custom checks can no longer be instantiated by Checkstyle. I was able to reproduce this error using the SevNTU plugin as well (stack trace below). Any ideas?
I can confirm this problem with another Plugin which was working before the upgrade to 8.0:
https://github.com/bjrke/JSR305CheckstylePlugin
Hi, I assume this to be related to a Checkstyle-internal change concerning the handling of checkstyle_packages.xml files.
Please note in the Exception message that there is a dot missing between the package and class name which Checkstyle core constructs from the checkstyle_packages.xml and the check name from the loaded configuration, e.g. com.puppycrawl.tools.checkstyle.checks.annotationJsr305Annotations
Please check with the Checkstyle core project where this change comes from. If my theory holds true, then custom checks will also not work with Checkstyle Ant/Maven tasks using Checkstyle 8.0.
Regards,
Lars
Possibly this change to PackageNamesLoader: https://github.com/checkstyle/checkstyle/commit/ddeb553834f10570089a033fa1ac1501b74ac358
I've included tests against checkstyle 8 which are working well:
https://travis-ci.org/bjrke/JSR305CheckstylePlugin
When I upgrade the gradle build of our big project to Checkstyle 8.0 it is working with a dev version of the plugin, too.
But I'll investigate the missing dot, perhaps there is a strange configuration issue.
I create https://github.com/checkstyle/checkstyle/issues/4885
Innate and Jan, it would be good if you reproduce problem as decribed at https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/.github/ISSUE_TEMPLATE.md to make sure that we have problem in Checkstyle, not in eclipse-cs.
Sevntu plugin is not upgraded to checkstyle8.0 and eclipce-cs8.0.0 yet.
It is rellay strange how me missed this as we run sevntu in CI.
I think the problem with loading is an eclipse-cs problem. Because as I already mentioned, I've upgraded the inheritance in https://github.com/bjrke/JSR305CheckstylePlugin/commit/e5fdf3c1340dbeb9bd5db79b9ad5448418b8dbb4 and I've tests against all known working checkstyle versions, including 8.0 and 8.1.
But I didn't released yet since eclipse-cs is not working.
To do more tests I need to setup a new environment because I need my eclipse for daily work.
I made some changes (i.e. adding plugin.xml) in the jar and now I get my package (with correct dots) in the error message, but it is still not loaded. So the checkstyle-metadata.xml is loading correct. Any ideas?
My custom check is also displayed with the correct dots in the error message but still is not loaded. Perhaps the incorrect dots in the error message was a red herring and not related to the class loading problem?
Yes, indeed the error message was misleading.
I did half an hour of debugging today and from what I can deduce there is something off with the classpath scanning for check class, introduced with https://github.com/checkstyle/checkstyle/issues/3607
However, I couldn't get to the bottom of this just yet - will need more time
For reference I ended up in https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtils.java#L55 which does not pick up the custom check classes in Eclipse.
Created https://github.com/checkstyle/checkstyle/issues/4916 - it appears as if a classpath scanning feature introduce in Checkstyle core recently cannot possibly work in Eclipse.
thank you for your effort debugging this issue!
do you think eclipse-cs could workaround this issue or do we have to wait for a solution from the checkstyle maintainers?
Unfortunately I don't think a workaround in eclipse-cs is feasible (or even possible).
In my eyes the current classpath scanning implementation offers no practical benefit over the long standing previous implementation while adding serious drawbacks. I hope the points brought forward are sufficient to convince the Checkstyle team to revert this change.
I have seen a pull request which might fix the problem: https://github.com/checkstyle/checkstyle/pull/5245
Checkstyle released fix for https://github.com/checkstyle/checkstyle/issues/4916 .
Lars, please upgrade to latest version of checkstyle to allow third-party checks.
eclipse-cs 8.5.0 based on Checkstyle 8.5 has been released.
that's a nice Christmas gift, thanks Lars :)
I can confirm: It is working, thank you!