/var/tmp $ javac --enable-preview --release 14 LocalRecordFailure.java
Note: LocalRecordFailure.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
/var/tmp $ cat config.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="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="${severity}" default="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<module name="TreeWalker">
<!-- We just need one module to get the parser to run -->
<module name="RedundantImport"/>
</module>
</module>
/var/tmp $ cat YOUR_FILE.java
class LocalRecordFailure {
public void doThing() {
// No error unless an annotation is present
@ProblemCauser
record Test(String hello, int world) {}
final var item = new Test("hi there", 22);
System.out.println(item);
}
}
@interface ProblemCauser {
}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-8.36.2-all.jar -c config.xml LocalRecordFailure.java
Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing LocalRecordFailure.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: com.puppycrawl.tools.checkstyle.api.CheckstyleException: IllegalStateException occurred while parsing file /home/zml/dev/checkstyle-localrecord-error/LocalRecordFailure.java.
at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:120)
at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:149)
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
Caused by: java.lang.IllegalStateException: /home/zml/dev/checkstyle-localrecord-error/LocalRecordFailure.java:7:9: expecting "class", found 'record'
at com.puppycrawl.tools.checkstyle.JavaParser$1.reportError(JavaParser.java:108)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeDefinition(GeneratedJavaRecognizer.java:424)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:212)
at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:114)
... 9 more
Caused by: /home/zml/dev/checkstyle-localrecord-error/LocalRecordFailure.java:7:9: expecting "class", found 'record'
at antlr.Parser.match(Parser.java:211)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.classDefinition(GeneratedJavaRecognizer.java:619)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.traditionalStatement(GeneratedJavaRecognizer.java:5985)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.statement(GeneratedJavaRecognizer.java:4814)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.compoundStatement(GeneratedJavaRecognizer.java:4543)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.field(GeneratedJavaRecognizer.java:3158)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.classBlock(GeneratedJavaRecognizer.java:3415)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.classDefinition(GeneratedJavaRecognizer.java:646)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeDefinitionInternal(GeneratedJavaRecognizer.java:561)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeDefinition(GeneratedJavaRecognizer.java:402)
... 11 more
Checkstyle ends with 1 errors.
I'd expect this file to parse successfully, but it doesn't. This is a minimal test case based on code from a test in my project. It seems to be triggered by the annotation on the local record -- the file parses fine without.
@nmancus1 Can you please help with it?
@zml2008 , thanks a lot for reporting issue.
Please let us know how can we run checkstyle validation (cli command) on your project ( https://github.com/SpongePowered/Configurate) ?
Is it possible to change version of Checkstyle from command line ? we will make fix and make sure that it works on your project without problems.
thank you for your help!
I've worked around the issue since the test works either way, but the reproduction has been pushed to a branch.
Normally I use the gradle plugin (configured here) -- but from cli you can run:
$ git switch bug/checkstyle-record
$ java -jar checkstyle-8.36.2-all.jar -c ./etc/checkstyle/checkstyle.xml ./core/src
to reproduce the issue. It looks like there are a few other formatting issues printed, but those are from checkstyle working correctly
let me know if you need anything else :)
@zml2008 , can you share how to run checkstyle on whole your project by gradle ?
we will verify that all other code is parse-able before releasing a fix.
Sure -- gradle needs to run with at least java 14 to activate the source set with problems, then to run checkstyle do:
$ ./gradlew checkstyleMain checkstyleTest checkstyleJava14Test --stacktrace
@zml2008 thanks for the great report. I am on this now. @romani should the new semaphore/travis job be in a separate PR?
new semaphore/travis job be in a separate PR?
Separate issue/PR .
fix is merged.