checkstyle/eclipse-cs

cannot initialize module - but Eclipse can find the extension

robtimus opened this issue · 9 comments

I have a Checkstyle extension, https://github.com/robtimus/checkstyle-extension. This works great in Maven. It used to work great in Eclipse as well, by simply adding it to the dropins folder. However, recently it stopped working. The thing is, Eclipse recognizes the plugin just fine. It's available under the Plug-ins tab of the Installation Details dialog, and it's also available for global Checkstyle configurations - if I create a new one, then configure it, the Checkstyle Extension category with my custom checks shows up, and I can add and configure these as needed. Actually performing the checks upon changing code doesn't work though: Eclipse shows an error ("Checkstyle execution failed due to an internal error. Please check the error log for details..."), and the logs show the following error:

com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module LicenseComment - Unable to instantiate 'LicenseComment' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.LicenseComment, com.puppycrawl.tools.checkstyle.checks.blocks.LicenseComment, com.puppycrawl.tools.checkstyle.checks.coding.LicenseComment, com.puppycrawl.tools.checkstyle.checks.design.LicenseComment, com.puppycrawl.tools.checkstyle.checks.header.LicenseComment, com.puppycrawl.tools.checkstyle.checks.imports.LicenseComment, com.puppycrawl.tools.checkstyle.checks.indentation.LicenseComment, com.puppycrawl.tools.checkstyle.checks.javadoc.LicenseComment, com.puppycrawl.tools.checkstyle.checks.metrics.LicenseComment, com.puppycrawl.tools.checkstyle.checks.modifier.LicenseComment, com.puppycrawl.tools.checkstyle.checks.naming.LicenseComment, com.puppycrawl.tools.checkstyle.checks.regexp.LicenseComment, com.puppycrawl.tools.checkstyle.checks.sizes.LicenseComment, com.puppycrawl.tools.checkstyle.checks.whitespace.LicenseComment, com.puppycrawl.tools.checkstyle.checks.LicenseComment, com.puppycrawl.tools.checkstyle.filefilters.LicenseComment, com.puppycrawl.tools.checkstyle.filters.LicenseComment, com.puppycrawl.tools.checkstyle.LicenseComment, com.github.robtimus.checkstyle.checks.LicenseComment, LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.annotation.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.blocks.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.coding.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.design.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.header.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.imports.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.indentation.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.javadoc.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.metrics.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.modifier.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.naming.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.regexp.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.sizes.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.whitespace.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.filefilters.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.filters.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.LicenseCommentCheck, com.github.robtimus.checkstyle.checks.LicenseCommentCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
	at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:481)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
	at net.sf.eclipsecs.core.builder.CheckerFactory.createCheckerInternal(CheckerFactory.java:238)
	at net.sf.eclipsecs.core.builder.CheckerFactory.createChecker(CheckerFactory.java:124)
	at net.sf.eclipsecs.core.builder.Auditor.runAudit(Auditor.java:139)
	at net.sf.eclipsecs.core.builder.CheckstyleBuilder.handleBuildSelection(CheckstyleBuilder.java:313)
	at net.sf.eclipsecs.core.builder.CheckstyleBuilder.build(CheckstyleBuilder.java:171)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1020)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:247)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:392)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:395)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:506)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:454)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:536)
	at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:524)
	at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:413)
	at org.eclipse.ui.actions.GlobalBuildAction$1.run(GlobalBuildAction.java:180)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'LicenseComment' class, it is also not possible to instantiate it as com.puppycrawl.tools.checkstyle.checks.annotation.LicenseComment, com.puppycrawl.tools.checkstyle.checks.blocks.LicenseComment, com.puppycrawl.tools.checkstyle.checks.coding.LicenseComment, com.puppycrawl.tools.checkstyle.checks.design.LicenseComment, com.puppycrawl.tools.checkstyle.checks.header.LicenseComment, com.puppycrawl.tools.checkstyle.checks.imports.LicenseComment, com.puppycrawl.tools.checkstyle.checks.indentation.LicenseComment, com.puppycrawl.tools.checkstyle.checks.javadoc.LicenseComment, com.puppycrawl.tools.checkstyle.checks.metrics.LicenseComment, com.puppycrawl.tools.checkstyle.checks.modifier.LicenseComment, com.puppycrawl.tools.checkstyle.checks.naming.LicenseComment, com.puppycrawl.tools.checkstyle.checks.regexp.LicenseComment, com.puppycrawl.tools.checkstyle.checks.sizes.LicenseComment, com.puppycrawl.tools.checkstyle.checks.whitespace.LicenseComment, com.puppycrawl.tools.checkstyle.checks.LicenseComment, com.puppycrawl.tools.checkstyle.filefilters.LicenseComment, com.puppycrawl.tools.checkstyle.filters.LicenseComment, com.puppycrawl.tools.checkstyle.LicenseComment, com.github.robtimus.checkstyle.checks.LicenseComment, LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.annotation.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.blocks.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.coding.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.design.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.header.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.imports.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.indentation.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.javadoc.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.metrics.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.modifier.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.naming.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.regexp.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.sizes.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.whitespace.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.checks.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.filefilters.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.filters.LicenseCommentCheck, com.puppycrawl.tools.checkstyle.LicenseCommentCheck, com.github.robtimus.checkstyle.checks.LicenseCommentCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
	at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:214)
	at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:471)
	... 20 more

However, one of the attempted classes is com.github.robtimus.checkstyle.checks.LicenseCommentCheck, and that class exists in my extension.

This problem started occurring a few days ago. I was still using Eclipse 2022-12 at the time, but upgrading to Eclipse 2023-06 didn't solve anything. I've tried running eclipse -clean, also after removing and re-adding my extension, but nothing has been working so far.

I've now downgraded the Checkstyle plugin to version 9.3 https://checkstyle.org/releasenotes.html#Release_9.3 , and it now works again, so I'm fairly confident that this is caused by something in the plugin.

romani commented

Do we have same problem with this extension https://github.com/sevntu-checkstyle/sevntu.checkstyle ?

I have not been able to find the time to upgrade the plugin and setup a new project with some rules from that extension. I will let you know the results when I get around to it.

I've done the following:

My Eclipse log now contains the following error:

!ENTRY net.sf.eclipsecs.core 4 0 2023-08-24 21:02:01.607
!MESSAGE Checkstyle Plugin: cannot initialize module TreeWalker - cannot initialize module com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck - Unable to instantiate 'com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck' class, it is also not possible to instantiate it as null. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
!STACK 0
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - cannot initialize module com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck - Unable to instantiate 'com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck' class, it is also not possible to instantiate it as null. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
	at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:481)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
	at net.sf.eclipsecs.core.builder.CheckerFactory.createCheckerInternal(CheckerFactory.java:238)
	at net.sf.eclipsecs.core.builder.CheckerFactory.createChecker(CheckerFactory.java:124)
	at net.sf.eclipsecs.core.builder.Auditor.runAudit(Auditor.java:139)
	at net.sf.eclipsecs.core.builder.CheckstyleBuilder.handleBuildSelection(CheckstyleBuilder.java:313)
	at net.sf.eclipsecs.core.builder.CheckstyleBuilder.build(CheckstyleBuilder.java:171)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1020)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:247)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:392)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:395)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:354)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:616)
	at org.eclipse.core.internal.resources.Project$1.run(Project.java:571)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2382)
	at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:609)
	at org.eclipse.core.internal.resources.Project.build(Project.java:121)
	at net.sf.eclipsecs.core.jobs.BuildProjectJob.run(BuildProjectJob.java:87)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck - Unable to instantiate 'com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck' class, it is also not possible to instantiate it as null. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
	at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:129)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
	at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:476)
	... 21 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck' class, it is also not possible to instantiate it as null. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
	at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:215)
	at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:120)
	... 23 more

Maven on the other hand works just fine, with sevntu-checks as dependency to the Maven Checkstyle plugin.

romani commented

@robtimus, so it works on eclipsecs 9.3 and not working on eclipsecs 10.0 (next release after 9.3)?

https://checkstyle.org/eclipse-cs/#!/releasenotes we changed min required Eclipse at 10.0.0 . f80470f Issue #340: change minimum Eclipse version to 2019-06 .

No big updates from library, except for min jdk bump.

@romani I had only tested with versions 9.3.0 (no error), 10.7.0 (auto-updated or something, error) and 10.9.3 (reinstall, error).

I have just finished testing with more versions, starting with 9.3.0 and going through the following procedure:

  • Install the plugin again, with the next minor version
  • When prompted to restart, shutdown instead
  • Manually remove the older version from the plugins folder (two versions were placed side-by-side)
  • Start Eclipse
  • Trigger a Checkstyle violation

Version 10.0.0 through 10.5.0 showed no errors, and the violation was correctly displayed. After the upgrade from 10.5.0 to 10.6.0 the error returned.

I've used the latest Eclipse (2023-06, 4.28.0) with the default JDK (Java 17).

romani commented

https://checkstyle.org/releasenotes.html#Release_10.5.0.

Allow 3rd party Check providers to group modules under custom parent module. Author: rnveach #11644

romani commented

@rnveach , do you experience any issues with sevntu usage in Eclipse?

I don't use sevntu in eclipse.
#316

https://checkstyle.org/releasenotes.html#Release_10.5.0.

Allow 3rd party Check providers to group modules under custom parent module. Author: rnveach #11644

That change seems to be more lenient, and it should not block my custom checks. Besides, that change got introduced in Checkstyle 10.5.0, a version that can load my checks just fine. Maven can also load them just fine.