Skip to content

[java] UnusedAssignment crashes with nested records #3224

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

Closed
vovkss opened this issue Apr 18, 2021 · 0 comments · Fixed by #3225
Closed

[java] UnusedAssignment crashes with nested records #3224

vovkss opened this issue Apr 18, 2021 · 0 comments · Fixed by #3225
Assignees
Labels
a:bug PMD crashes or fails to analyse a file.
Milestone

Comments

@vovkss
Copy link
Contributor

vovkss commented Apr 18, 2021

Affects PMD Version:

6.33

Description:

If there's a nested record, the UnusedAssignment rule fails with an exception.
This happens for both private and public records.

Exception Stacktrace:

java.lang.NullPointerException: Cannot invoke "net.sourceforge.pmd.lang.java.ast.AccessNode.isStatic()" because the return value of "net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration.getAccessNodeParent()" is null
    at net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedAssignmentRule$ReachingDefsVisitor.useAllSelfFields (UnusedAssignmentRule.java:1102)
    at net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedAssignmentRule$ReachingDefsVisitor.processInitializers (UnusedAssignmentRule.java:1096)
    at net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedAssignmentRule$ReachingDefsVisitor.visitTypeBody (UnusedAssignmentRule.java:1036)
    at net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedAssignmentRule$ReachingDefsVisitor.visitTypeBody (UnusedAssignmentRule.java:1047)
    at net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedAssignmentRule$ReachingDefsVisitor.visit (UnusedAssignmentRule.java:1023)
    at net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody.jjtAccept (ASTClassOrInterfaceBody.java:35)
    at net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedAssignmentRule$ReachingDefsVisitor.visit (UnusedAssignmentRule.java:328)
    at net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter.visit (JavaParserVisitorAdapter.java:23)
    at net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration.jjtAccept (ASTClassOrInterfaceDeclaration.java:56)
    at net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedAssignmentRule.visit (UnusedAssignmentRule.java:158)
    at net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit.jjtAccept (ASTCompilationUnit.java:44)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visitAll (AbstractJavaRule.java:163)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply (AbstractJavaRule.java:157)
    at net.sourceforge.pmd.lang.internal.DefaultRulechainVisitor.visit (DefaultRulechainVisitor.java:26)
    at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll (AbstractRuleChainVisitor.java:99)
    at net.sourceforge.pmd.RuleChain.apply (RuleChain.java:72)
    at net.sourceforge.pmd.RuleSets.apply (RuleSets.java:160)
    at net.sourceforge.pmd.SourceCodeProcessor.processSource (SourceCodeProcessor.java:200)
    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache (SourceCodeProcessor.java:113)
    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:264)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1130)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:630)
    at java.lang.Thread.run (Thread.java:831)

Code Sample demonstrating the issue:

class Test {
    public record NestedRecord(int x, int y) {
    }
}

Running PMD through: Maven

JDK 16.

@vovkss vovkss added the a:bug PMD crashes or fails to analyse a file. label Apr 18, 2021
@oowekyala oowekyala added this to the 6.34.0 milestone Apr 18, 2021
@oowekyala oowekyala self-assigned this Apr 18, 2021
adangel added a commit to adangel/pmd that referenced this issue Apr 19, 2021
adangel added a commit to adangel/pmd that referenced this issue Apr 19, 2021
…Crash

[java] Fix pmd#3224 - UnusedAssignment crashes with nested records pmd#3225
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants