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 try-with-resources and qualified resource #3697

Closed
cbfiddle opened this issue Dec 23, 2021 · 2 comments · Fixed by #3774
Closed

[java] Parsing error with try-with-resources and qualified resource #3697

cbfiddle opened this issue Dec 23, 2021 · 2 comments · Fixed by #3774
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

@cbfiddle
Copy link

cbfiddle commented Dec 23, 2021

Affects PMD Version: 6.41.0
Description: PMD fails to parse the following file
Exception Stacktrace:

<error filename="/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/lib/src.zip:java.base/sun/security/ssl/SSLSocketImpl.java" msg="PMDException: Error while parsing /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/lib/src.zip:java.base/sun/security/ssl/SSLSocketImpl.java">
<![CDATA[net.sourceforge.pmd.PMDException: Error while parsing /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/lib/src.zip:java.base/sun/security/ssl/SSLSocketImpl.java
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:124)
	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:85)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:29)
	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.java.ast.ParseException: Encountered " ")" ") "" at line 798, column 44.
Was expecting one of:
    "this" ...
    <IDENTIFIER> ...
    "@" ...
    <IDENTIFIER> ...
    
	at net.sourceforge.pmd.lang.java.ast.JavaParser.generateParseException(JavaParser.java:13532)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_consume_token(JavaParser.java:13416)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.VariableDeclaratorId(JavaParser.java:1974)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Resource(JavaParser.java:6876)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Resources(JavaParser.java:6809)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ResourceSpecification(JavaParser.java:6773)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.TryStatement(JavaParser.java:6715)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Statement(JavaParser.java:5508)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.BlockStatement(JavaParser.java:5671)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Block(JavaParser.java:5588)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Statement(JavaParser.java:5465)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.IfStatement(JavaParser.java:6278)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Statement(JavaParser.java:5481)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.BlockStatement(JavaParser.java:5671)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Block(JavaParser.java:5588)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Statement(JavaParser.java:5465)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.IfStatement(JavaParser.java:6283)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Statement(JavaParser.java:5481)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.BlockStatement(JavaParser.java:5671)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Block(JavaParser.java:5588)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.MethodDeclaration(JavaParser.java:2130)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBodyDeclaration(JavaParser.java:1811)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:1764)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:905)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.TypeDeclaration(JavaParser.java:807)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.CompilationUnit(JavaParser.java:527)
	at net.sourceforge.pmd.lang.java.AbstractJavaParser.parse(AbstractJavaParser.java:62)
	at net.sourceforge.pmd.lang.AbstractParser.doParse(AbstractParser.java:44)
	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:

import java.io.InputStream;
public class Foo {
    public InputStream in;
    public void bar() {
        Foo f = this;
       
        try (f.in) {
        }

        try (this.in) {
        }

    }
}

File: java.base/sun/security/ssl/SSLSocketImpl.java

Maybe this here? https://github.com/openjdk/jdk/blob/dfacda488bfbe2e11e8d607a6d08527710286982/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java#L798

@cbfiddle cbfiddle added the a:bug PMD crashes or fails to analyse a file. label Dec 23, 2021
@jsotuyod

This comment has been minimized.

@cbfiddle

This comment has been minimized.

@jsotuyod jsotuyod added in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception and removed was:invalid labels Dec 23, 2021
@jsotuyod jsotuyod reopened this Dec 23, 2021
@adangel adangel changed the title parsing error [java] Parsing error Jan 14, 2022
@adangel adangel changed the title [java] Parsing error [java] Parsing error with try-with-resources and qualified resource Jan 14, 2022
@oowekyala oowekyala added this to the 6.43.0 milestone Jan 30, 2022
adangel added a commit to adangel/pmd that referenced this issue Feb 19, 2022
[java] Fix pmd#3697 - lookahead error in concise resource spec pmd#3774
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