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

Parse exception for RAW string template (Java 21+) #14793

Closed
diversit opened this issue Apr 15, 2024 · 3 comments
Closed

Parse exception for RAW string template (Java 21+) #14793

diversit opened this issue Apr 15, 2024 · 3 comments
Labels

Comments

@diversit
Copy link

diversit commented Apr 15, 2024

In Java 21/22, when using a String template with a raw String, checkstyle fails with a parsing error:

Maven checkstyle output:

An error has occurred in Checkstyle report generation.: Failed during checkstyle configuration: 
Exception was thrown while processing /path/to/a/java/Class.java: IllegalStateException occurred 
while parsing file /path/to/a/java/Class.java. 90:24: mismatched input '(' expecting ';': InputMismatchException

I have verified this issue by adding

   String result11 = STR."""
                Hello World
                """;

to the Checkstyle's com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateBasic.java test case.

See updated test case InputStringTemplateBasic.java

The test fails with
Java21AstRegressionTest.testBasicStringTemplate:42->AbstractTreeTestSupport.verifyAst:77->AbstractTreeTestSupport.verifyAst:57 » Checkstyle IllegalStateException occurred while parsing file /Users/dhl/Project/others/checkstyle/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateBasic.java

Using a raw string with a String Template is valid syntax. See Java 21 String Templates: Multiline String Templates and Java 22 String Templates: Multiline String Template

Also using StringTemplate.RAW, which is an alternative notation of STR."""..""" fails with a parse error.
Java Api Docs StringTemplate

import static java.lang.StringTemplate.RAW;

    // raw string
    String result11 = RAW."""
            Hello \{name}
            """;

Tested with:

Java: 21 and 22
Checkstyle: 10.14 and 10.15

diversit added a commit to diversit/checkstyle that referenced this issue Apr 15, 2024
@mahfouz72
Copy link
Member

Checkstyle is currently unable to parse this syntax. there is an open issue for this #14195 (comment)
complete support for all java 21 new syntax (parsing and checkstyle checks) will be done by the summer.

@romani
Copy link
Member

romani commented Apr 17, 2024

Also using StringTemplate.RAW, which is an alternative notation of STR.""".."""

@nrmancuso ,
Do we allow not STR ?

@romani romani changed the title Parse exception for raw string template (Java 21+) Parse exception for RAW string template (Java 21+) Apr 17, 2024
@nrmancuso
Copy link
Member

Also using StringTemplate.RAW, which is an alternative notation of STR.""".."""

@nrmancuso , Do we allow not STR ?

This example is not valid syntax. Text blocks must begin with three quotes and a newline character.

I am removing the approved label since this is a duplicate of #14195

It is unlikely that we will ever support this syntax, since Java themselves have dropped it: #14805

I suggest that we close this issue and continue any discussion at #14195

@romani romani closed this as completed Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants