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

Custom checks broken with Checkstyle 8.0 #4885

Closed
lkoe opened this issue Aug 2, 2017 · 6 comments
Closed

Custom checks broken with Checkstyle 8.0 #4885

lkoe opened this issue Aug 2, 2017 · 6 comments

Comments

@lkoe
Copy link
Member

lkoe commented Aug 2, 2017

Please note this bug against eclipse-cs-8.0.0, which I believe to be an issue in Checkstyle core introduced somewhere after 7.6 (confirmed in 8.0):
https://sourceforge.net/p/eclipse-cs/discussion/274377/thread/4ab4f095/?limit=25#1334

Due to a "recent" change to PackageNamesLoader (supposedly this commit ddeb553) the class name guessing algorithm based on checkstyle_packages.xml files is not working properly anymore.
Please note the missing dot between package name and class name in the error message:

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: 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.

@rnveach
Copy link
Member

rnveach commented Aug 2, 2017

@lkoe Please provide us information to reproduce problem like check source, and how you are calling Checkstyle with it.
See http://checkstyle.sourceforge.net/report_issue.html#How_to_report_a_bug

@rnveach
Copy link
Member

rnveach commented Aug 3, 2017

Please note the missing dot between package name and class name in the error message
com.puppycrawl.tools.checkstyle.checks.annotationJsr305Annotations

I missed this when reading the issue before.
I can reproduce the issue with the current release and CLI.

$ cat TestClass.java
public class TestClass {
    void method() {
    }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="Jsr305Annotations" />
    </module>
</module>

$ java -jar checkstyle-8.1-all.jar -c TestConfig.xml TestClass.java
com.puppycrawl.tools.checkstyle.api.CheckstyleException: 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.
    at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:461)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)
    at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:504)
    at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:431)
    at com.puppycrawl.tools.checkstyle.Main.main(Main.java:209)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: 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.
    at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:184)
    at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:168)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:171)
    at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:456)
    ... 4 more
Checkstyle ends with 1 errors.

com.puppycrawl.tools.checkstyle.checks.annotationJsr305Annotations

I can't reproduce this issue in our tests. The ones I have looked at have the periods, so I am not sure why the jar is not showing them. The nightly jar produces the same result as the release.

@rnveach
Copy link
Member

rnveach commented Aug 3, 2017

Looking at the end of the error displayed is:

com.puppycrawl.tools.checkstyle.Jsr305AnnotationsCheck

I can produce the invalid display with modifying the test PackageObjectFactoryTest.testCreateObjectFromFullModuleNamesWithException

@lkoe List of tried results may just be a display problem, and not a result of failing to load the check. We still need your details to determine why your check won't load if it is defined correctly.

@romani
Copy link
Member

romani commented Aug 3, 2017

fix for correct message print is provided.
We still need more details on class location to prove that it can not be loaded but it present in classpath.

@bjrke
Copy link

bjrke commented Aug 3, 2017

As maintainer of Jsr305Annotations I can confirm that the current master of the plugin is able to run against checkstyle 8 as seen in the tests https://travis-ci.org/bjrke/JSR305CheckstylePlugin.
Dispite https://github.com/bjrke/JSR305CheckstylePlugin/releases/download/0.5.0/JSR305CheckstylePlugin-0.5.0.jar is not working since it still uses the deprecated and in 8 removed base class Checks which is fixed by bjrke/JSR305CheckstylePlugin@e5fdf3c.
But I didn't released yet because eclipse-cs is not working.

Anyway, the class names in output pasted by @lkoe was generated by me in the eclipse-cs environment.

@romani
Copy link
Member

romani commented Aug 3, 2017

ok , I am closing this issue for now, if some other problems found it could be reopened or it is better to create new issue.

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

No branches or pull requests

4 participants