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

[java] Parsing error with textblock containing quote followed by two backslashes #4364

Closed
liamsharp opened this issue Jan 26, 2023 · 1 comment · Fixed by #4366
Closed

[java] Parsing error with textblock containing quote followed by two backslashes #4364

liamsharp opened this issue Jan 26, 2023 · 1 comment · Fixed by #4366
Assignees
Labels
a:bug PMD crashes or fails to analyse a file. in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception
Milestone

Comments

@liamsharp
Copy link

Affects PMD Version:

6.53.0

Description:

Parsing this code:

final static String content = """
    <div class="\\invalid-class></div>
    """;

Exception Stacktrace:

<error filename="Testing.java" msg="PMDException: Error while processing Testing.java">
<![CDATA[net.sourceforge.pmd.PMDException: Error while processing /Testing.java
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:128)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:100)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:62)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:89)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:30)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error at line 6, column 38.  Encountered: "\n" (10), after : "\"" (in lexical state 0)
	at net.sourceforge.pmd.lang.java.ast.JavaParserTokenManager.getNextToken(JavaParserTokenManager.java:2388)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_consume_token(JavaParser.java:14327)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Literal(JavaParser.java:5396)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.PrimaryPrefix(JavaParser.java:4914)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.PrimaryExpression(JavaParser.java:4720)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.PostfixExpression(JavaParser.java:4542)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.UnaryExpressionNotPlusMinus(JavaParser.java:4440)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.UnaryExpression(JavaParser.java:4317)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.MultiplicativeExpression(JavaParser.java:4232)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.AdditiveExpression(JavaParser.java:4179)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ShiftExpression(JavaParser.java:4122)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.RelationalExpression(JavaParser.java:4061)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.InstanceOfExpression(JavaParser.java:3982)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.EqualityExpression(JavaParser.java:3680)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.AndExpression(JavaParser.java:3640)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ExclusiveOrExpression(JavaParser.java:3600)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.InclusiveOrExpression(JavaParser.java:3560)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ConditionalAndExpression(JavaParser.java:3520)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ConditionalOrExpression(JavaParser.java:3480)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ConditionalExpression(JavaParser.java:3442)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Expression(JavaParser.java:3301)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.VariableInitializer(JavaParser.java:2072)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.VariableDeclarator(JavaParser.java:1945)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.FieldDeclaration(JavaParser.java:1897)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBodyDeclaration(JavaParser.java:1847)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:1802)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:930)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.TypeDeclaration(JavaParser.java:832)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.CompilationUnit(JavaParser.java:552)
	at net.sourceforge.pmd.lang.java.AbstractJavaParser.parse(AbstractJavaParser.java:62)
	at net.sourceforge.pmd.lang.AbstractParser.doParse(AbstractParser.java:45)
	at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:136)
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:200)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:118)
	... 10 more
]]>
</error>

Code Sample demonstrating the issue:

public class Testing
{

    final static String content = """
        <div class="\\invalid-class></div>
        """;

    
}

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

mvn compile

Running PMD through: Maven

@liamsharp liamsharp added the a:bug PMD crashes or fails to analyse a file. label Jan 26, 2023
@oowekyala oowekyala added the in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception label Jan 26, 2023
@jsotuyod
Copy link
Member

This issue is also present in PMD 7.

jsotuyod added a commit to Monits/pmd that referenced this issue Jan 26, 2023
@jsotuyod jsotuyod self-assigned this Jan 26, 2023
@jsotuyod jsotuyod added this to the 6.54.0 milestone Jan 26, 2023
@jsotuyod jsotuyod changed the title [java] PMDException with java textblock containing quote followed by two backslashes [java] Parsing error with textblock containing quote followed by two backslashes Jan 26, 2023
rdesgroppes added a commit to rdesgroppes/rules_jvm that referenced this issue Apr 26, 2023
Currently shipped PMD version is at 6.46.0, released in May 2022.
Since then, a handful of fixes & enhancements got released, among which:
- pmd/pmd#3936 in 6.47.0
- pmd/pmd#4015 in 6.48.0
- pmd/pmd#4082 in 6.49.0
- pmd/pmd#4085 in 6.50.0
- pmd/pmd#4139 in 6.51.0
- pmd/pmd#4152 in 6.52.0
- pmd/pmd#4266 in 6.53.0
- pmd/pmd#4364 in 6.54.0
- pmd/pmd#4333 in 6.55.0

The latter also
[states](https://docs.pmd-code.org/pmd-doc-6.55.0/pmd_release_notes.html#pmd-7-development)
that:
> This release is the last planned release of PMD 6. The first version
> 6.0.0 was released in December 2017. Over the course of more than 5
> years we published almost every month a new minor version of PMD 6
> with new features and improvements.

The present change therefore bumps the shipped PMD version to 6.55.0 so
as to benefit from its last improvements, before envisioning an upgrade
to PMD 7, [when ready](https://github.com/pmd/pmd/milestone/19).

Closes bazel-contrib#176.
rdesgroppes added a commit to rdesgroppes/rules_jvm that referenced this issue Apr 26, 2023
closes bazel-contrib#176.

Currently shipped PMD version is at 6.46.0, released in May 2022.
Since then, a handful of fixes & enhancements got released, among which:
- pmd/pmd#3936 in 6.47.0
- pmd/pmd#4015 in 6.48.0
- pmd/pmd#4082 in 6.49.0
- pmd/pmd#4085 in 6.50.0
- pmd/pmd#4139 in 6.51.0
- pmd/pmd#4152 in 6.52.0
- pmd/pmd#4266 in 6.53.0
- pmd/pmd#4364 in 6.54.0
- pmd/pmd#4333 in 6.55.0

The latter also
[states](https://docs.pmd-code.org/pmd-doc-6.55.0/pmd_release_notes.html#pmd-7-development)
that:
> This release is the last planned release of PMD 6. The first version
> 6.0.0 was released in December 2017. Over the course of more than 5
> years we published almost every month a new minor version of PMD 6
> with new features and improvements.

The present change therefore bumps the shipped PMD version to 6.55.0 so
as to benefit from its last improvements, before envisioning an upgrade
to PMD 7, [when ready](https://github.com/pmd/pmd/milestone/19).
illicitonion pushed a commit to bazel-contrib/rules_jvm that referenced this issue Apr 26, 2023
closes #176.

Currently shipped PMD version is at 6.46.0, released in May 2022.
Since then, a handful of fixes & enhancements got released, among which:
- pmd/pmd#3936 in 6.47.0
- pmd/pmd#4015 in 6.48.0
- pmd/pmd#4082 in 6.49.0
- pmd/pmd#4085 in 6.50.0
- pmd/pmd#4139 in 6.51.0
- pmd/pmd#4152 in 6.52.0
- pmd/pmd#4266 in 6.53.0
- pmd/pmd#4364 in 6.54.0
- pmd/pmd#4333 in 6.55.0

The latter also
[states](https://docs.pmd-code.org/pmd-doc-6.55.0/pmd_release_notes.html#pmd-7-development)
that:
> This release is the last planned release of PMD 6. The first version
> 6.0.0 was released in December 2017. Over the course of more than 5
> years we published almost every month a new minor version of PMD 6
> with new features and improvements.

The present change therefore bumps the shipped PMD version to 6.55.0 so
as to benefit from its last improvements, before envisioning an upgrade
to PMD 7, [when ready](https://github.com/pmd/pmd/milestone/19).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file. in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants