GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Parse exception when using "record" as variable name · Issue #3145 · pmd/pmd

[java] Parse exception when using "record" as variable name #3145

New issue
Copy link
New issue
Copy link
Closed
#3150
Closed
[java] Parse exception when using "record" as variable name#3145
#3150
Copy link
Assignees
oowekyala
Labels
a:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception
Milestone
6.33.0

Description

@maikelsteneker
maikelsteneker
opened on Mar 1, 2021
Issue body actions

Affects PMD Version: 6.32.0

Make sure, to test with the latest PMD version.

Description:

When using a variable named record, PMD fails with an exception. I imagine this is because the keyword record is reserved for JDK 16 support, but the source file actually compiles fine using the latest JDK 16 preview.

Exception Stacktrace:

net.sourceforge.pmd.PMDException: Error while parsing /tmp/test/RecordExample.java
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:116)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:95)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:57)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:85)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:29)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: net.sourceforge.pmd.lang.java.ast.ParseException: Encountered " "." ". "" at line 6, column 15.
Was expecting:
    <IDENTIFIER> ...
    
	at net.sourceforge.pmd.lang.java.ast.JavaParser.generateParseException(JavaParser.java:13324)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_consume_token(JavaParser.java:13208)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.RecordDeclaration(JavaParser.java:1304)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.LocalTypeDecl(JavaParser.java:5605)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.BlockStatement(JavaParser.java:5566)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.Block(JavaParser.java:5488)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.MethodDeclaration(JavaParser.java:2104)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBodyDeclaration(JavaParser.java:1785)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:1738)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:879)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.TypeDeclaration(JavaParser.java:781)
	at net.sourceforge.pmd.lang.java.ast.JavaParser.CompilationUnit(JavaParser.java:501)
	at net.sourceforge.pmd.lang.java.AbstractJavaParser.parse(AbstractJavaParser.java:62)
	at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:127)
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:191)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:113)
	... 10 more

Code Sample demonstrating the issue:

import java.util.Map;
import java.util.HashMap;
public class RecordExample {
    public void main(String... args) {
        final Map<String, String> record = new HashMap<>();
        record.put("key", "value");
    }
}

Steps to reproduce:

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

  1. Simply run PMD on the source code above (pmd -R rulesets/java/quickstart.xml -f xml -d /tmp/test/).

Running PMD through: CLI

Activity

  1. maikelsteneker
    added
    a:bugPMD crashes or fails to analyse a file.
    on Mar 1, 2021
  2. oowekyala commented on Mar 1, 2021

    @oowekyala
    oowekyala
    on Mar 1, 2021
    Member
    More actions

    Thanks for the report.

    This is related to local record declarations, the lookahead is probably wrong

  3. oowekyala
    added
    in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception
    on Mar 1, 2021
  4. oowekyala
    modified the milestones: 7.0.0, 6.33.0 on Mar 1, 2021
  5. oowekyala
    self-assigned this
    on Mar 4, 2021
  6. oowekyala
    added a commit that references this issue on Mar 4, 2021

    Fix pmd#3145 - parse exception with local records

    This issue will close once commit a0e8107 is merged into the 'main' branch.
    a0e8107
  7. adangel
    closed this as completedin a0e8107on Mar 5, 2021
  8. adangel
    added 2 commits that reference this issue on Mar 5, 2021

    [doc] Update release notes (#3145, #3150)

    3ec49a2

    Merge pull request #3150 from oowekyala:issue3145-local-record

    1905ea6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @oowekyala
    oowekyala

Labels

a:bugPMD crashes or fails to analyse a file.in:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception

Type

No type

Projects

No projects

    Milestone

    • 6.33.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.