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

Checkstyle fails to parse unnamed variable #13988

Closed
nrmancuso opened this issue Nov 3, 2023 · 4 comments · Fixed by #14025
Closed

Checkstyle fails to parse unnamed variable #13988

nrmancuso opened this issue Nov 3, 2023 · 4 comments · Fixed by #14025

Comments

@nrmancuso
Copy link
Member

Reading: https://openjdk.org/jeps/456#:~:text=An%20unnamed%20variable%20is%20declared,parameter%20in%20a%20lambda%20expression.

Summary
Enhance the Java programming language with unnamed variables and unnamed patterns, which can be used when variable declarations or nested patterns are required but never used. Both are denoted by the underscore character, _.

Example:

➜  src cat UnnamedVariable.java                        
public class UnnamedVariable {
    record R(int x) {}
    void m(Object o) {
        if (o instanceof R(_)) {}
    }
}
➜  src javac --release 21 --enable-preview UnnamedVariable.java 
Note: UnnamedVariable.java uses preview features of Java SE 21.
Note: Recompile with -Xlint:preview for details.
➜  src java -jar checkstyle-10.12.3-all.jar -t UnnamedVariable.java 
com.puppycrawl.tools.checkstyle.api.CheckstyleException: IllegalStateException occurred while parsing file /home/nick/IdeaProjects/tester/src/UnnamedVariable.java.
        at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:105)
        at com.puppycrawl.tools.checkstyle.JavaParser.parseFileText(JavaParser.java:122)
        at com.puppycrawl.tools.checkstyle.JavaParser.parseFile(JavaParser.java:142)
        at com.puppycrawl.tools.checkstyle.AstTreeStringPrinter.printFileAst(AstTreeStringPrinter.java:65)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:291)
        at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:195)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:130)
Caused by: java.lang.IllegalStateException: 4:26: mismatched input '(' expecting ')'
        at com.puppycrawl.tools.checkstyle.JavaParser$CheckstyleErrorListener.syntaxError(JavaParser.java:255)
        at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
        at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544)
        at org.antlr.v4.runtime.DefaultErrorStrategy.reportInputMismatch(DefaultErrorStrategy.java:327)
        at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:139)
        at com.puppycrawl.tools.checkstyle.CheckstyleParserErrorStrategy.recoverInline(CheckstyleParserErrorStrategy.java:38)
        at org.antlr.v4.runtime.Parser.match(Parser.java:208)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.parExpression(JavaLanguageParser.java:8753)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.statement(JavaLanguageParser.java:6769)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.blockStatement(JavaLanguageParser.java:6198)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.block(JavaLanguageParser.java:6101)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.methodBody(JavaLanguageParser.java:2940)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.methodDeclaration(JavaLanguageParser.java:2898)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.memberDeclaration(JavaLanguageParser.java:2745)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.classBodyDeclaration(JavaLanguageParser.java:2671)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.classBody(JavaLanguageParser.java:2477)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.classDeclaration(JavaLanguageParser.java:1096)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.types(JavaLanguageParser.java:753)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.typeDeclaration(JavaLanguageParser.java:667)
        at com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageParser.compilationUnit(JavaLanguageParser.java:414)
        at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:99)
        ... 6 more
Caused by: org.antlr.v4.runtime.InputMismatchException
        ... 22 more
Checkstyle ends with 1 errors.


@nrmancuso nrmancuso self-assigned this Nov 3, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Nov 13, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Nov 13, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Nov 13, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Nov 13, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Nov 28, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 28, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 31, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 31, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 31, 2023
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 2, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 2, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 11, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 25, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 25, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 25, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 25, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 25, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 25, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 27, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 28, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 30, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jan 31, 2024
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Feb 2, 2024
@github-actions github-actions bot added this to the 10.13.1 milestone Feb 4, 2024
@nrmancuso
Copy link
Member Author

Completed via #14025 (review)

@rnveach
Copy link
Member

rnveach commented Feb 4, 2024

@nrmancuso Has there been any review on which modules should be changed for this new antlr?

@nrmancuso
Copy link
Member Author

Yes, I will open a WIP issue to track this.

@nrmancuso
Copy link
Member Author

Done at #14444

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

Successfully merging a pull request may close this issue.

3 participants