Skip to content
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

Not working with spring-javaformat #550

Closed
ttddyy opened this issue Feb 12, 2022 · 5 comments
Closed

Not working with spring-javaformat #550

ttddyy opened this issue Feb 12, 2022 · 5 comments

Comments

@ttddyy
Copy link

ttddyy commented Feb 12, 2022

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 more

After reading #510, I added spring-javaformat-checkstyle-0.0.31.jar as "Third-Party Checks".

image

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

@tsjensen
Copy link
Contributor

You may have to press Apply in between, i.e. after adding the 3rd party jar.

@ttddyy
Copy link
Author

ttddyy commented 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
Copy link
Contributor

Ok, just an idea, I'll be quiet then. 😊

@jshiell
Copy link
Owner

jshiell commented 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.

Screenshot 2022-02-14 at 19 21 43

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 src

@ttddyy
Copy link
Author

ttddyy commented Feb 15, 2022

Oh, ic. Thanks now it works!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants