Repository navigation
Closed
Description
I was trying to apply checkstyle rules with spring-javaformat.
IntelliJ IDEA: 2021.3.2 (Ultimate Edition)
Checkstyle Plugin: 5.61.0
Spring Javaformat: 0.0.31
Based on here, I have created this checkstyle.xml:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="com.puppycrawl.tools.checkstyle.Checker">
<module name="io.spring.javaformat.checkstyle.SpringChecks" />
</module>When I tried to add this checkstyle file, received the following exceptions:
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module io.spring.javaformat.checkstyle.SpringChecks - Unable to instantiate 'io.spring.javaformat.checkstyle.SpringChecks' 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:473)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
at org.infernus.idea.checkstyle.service.cmd.OpCreateChecker.execute(OpCreateChecker.java:61)
at org.infernus.idea.checkstyle.service.cmd.OpCreateChecker.execute(OpCreateChecker.java:26)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.executeCommand(CheckstyleActionsImpl.java:130)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.createChecker(CheckstyleActionsImpl.java:60)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.createChecker(CheckstyleActionsImpl.java:51)
at org.infernus.idea.checkstyle.checker.CheckerFactoryWorker.run(CheckerFactoryWorker.java:46)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'io.spring.javaformat.checkstyle.SpringChecks' 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.Checker.setupChild(Checker.java:463)
... 7 moreAfter reading #510, I added spring-javaformat-checkstyle-0.0.31.jar as "Third-Party Checks".
It passed the above, but still failed with:
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'io.spring.javaformat.checkstyle.check.SpringLeadingWhitespaceCheck' class, it is also not possible to instantiate it as null.
I see SpringLeadingWhitespaceCheck exists in the spring-javaformat-checkstyle-0.0.31.jar.
> jar tvf spring-javaformat-checkstyle-0.0.31.jar | grep SpringLeadingWhitespaceCheck
4149 Wed Feb 02 23:03:28 PST 2022 io/spring/javaformat/checkstyle/check/SpringLeadingWhitespaceCheck.class
Here is the complete error:
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module io.spring.javaformat.checkstyle.check.SpringLeadingWhitespaceCheck - Unable to instantiate 'io.spring.javaformat.checkstyle.check.SpringLeadingWhitespaceCheck' 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:128)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
at io.spring.javaformat.checkstyle.SpringConfigurationLoader.initialize(SpringConfigurationLoader.java:92)
at io.spring.javaformat.checkstyle.SpringConfigurationLoader.createModule(SpringConfigurationLoader.java:81)
at io.spring.javaformat.checkstyle.SpringConfigurationLoader.load(SpringConfigurationLoader.java:69)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at io.spring.javaformat.checkstyle.SpringConfigurationLoader.load(SpringConfigurationLoader.java:55)
at io.spring.javaformat.checkstyle.SpringChecks.finishLocalSetup(SpringChecks.java:103)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:197)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:468)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
at org.infernus.idea.checkstyle.service.cmd.OpCreateChecker.execute(OpCreateChecker.java:61)
at org.infernus.idea.checkstyle.service.cmd.OpCreateChecker.execute(OpCreateChecker.java:26)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.executeCommand(CheckstyleActionsImpl.java:130)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.createChecker(CheckstyleActionsImpl.java:60)
at org.infernus.idea.checkstyle.service.CheckstyleActionsImpl.createChecker(CheckstyleActionsImpl.java:51)
at org.infernus.idea.checkstyle.checker.CheckerFactoryWorker.run(CheckerFactoryWorker.java:46)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'io.spring.javaformat.checkstyle.check.SpringLeadingWhitespaceCheck' 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 io.spring.javaformat.checkstyle.FilteredModuleFactory.createModule(FilteredModuleFactory.java:50)
at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:119)
... 23 more
Metadata
Metadata
Assignees
Labels
No labels

Activity
tsjensen commentedon Feb 12, 2022
You may have to press Apply in between, i.e. after adding the 3rd party jar.
ttddyy commentedon Feb 12, 2022
@tsjensen Yes, I've done that. So, it's already listed when I open the preference window, but the error still shows up.
tsjensen commentedon Feb 12, 2022
Ok, just an idea, I'll be quiet then. 😊
jshiell commentedon Feb 14, 2022
Sorry for the delay, I spent the weekend trapped stripping wallpaper 😢
The problem is that your Spring module is spread over two JAR files - MVNRepository shows the dependency on spring-javaformat-config.
After adding both JARs it works for me.
Likewise, you need to do the same when running it via the CLI:
java -cp test-configs/spring-javaformat-checkstyle-0.0.31.jar:test-configs/spring-javaformat-config-0.0.31.jar:$HOME/Downloads/checkstyle-9.3-all.jar com.puppycrawl.tools.checkstyle.Main -c test-configs/issue-550.xml srcttddyy commentedon Feb 15, 2022
Oh, ic. Thanks now it works!!