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

DesignForExtension check crashes CheckStyle if an undocumented non-final method is present in a record (Java 14 + Java 15) #8810

Closed
vovkss opened this issue Sep 7, 2020 · 1 comment

Comments

@vovkss
Copy link

vovkss commented Sep 7, 2020

Check documentation: https://checkstyle.sourceforge.io/config_design.html#DesignForExtension

/var/tmp $ javac WhatsThis.java --enable-preview --release=15
Note: WhatsThis.java uses preview language features.
Note: Recompile with -Xlint:preview for details.


/var/tmp $ cat config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="DesignForExtension"/>
  </module>
</module>


/var/tmp $ cat WhatsThis.java
public record WhatsThis(
    String whatever
) {
    @Override
    public String toString() {
        return "Whatever " + whatever;
    }
}


/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-8.36-all.jar -c config.xml WhatsThis.java
Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing WhatsThis.java
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:311)
        at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:221)
        at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:408)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:331)
        at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:190)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:125)
Caused by: java.lang.NullPointerException: Cannot invoke "com.puppycrawl.tools.checkstyle.api.DetailAST.getType()" because "searchAST" is null
        at com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck.getNearestClassOrEnumDefinition(DesignForExtensionCheck.java:437)
        at com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck.visitToken(DesignForExtensionCheck.java:278)
        at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:340)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:451)
        at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:278)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:155)
        at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:87)
        at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:337)
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:298)
        ... 5 more
Checkstyle ends with 1 errors.

Since records are implicitly final, the DesignForExtension check should ignore records completely.

@romani
Copy link
Member

romani commented Sep 10, 2020

Fix is merged

@romani romani closed this as completed Sep 10, 2020
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

2 participants