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] ConstructorCallsOverridableMethodRule IndexOutOfBoundsException on a java16 record · Issue #3305 · pmd/pmd

[java] ConstructorCallsOverridableMethodRule IndexOutOfBoundsException on a java16 record #3305

New issue
Copy link
New issue
Copy link
Closed
#3348
Closed
[java] ConstructorCallsOverridableMethodRule IndexOutOfBoundsException on a java16 record#3305
#3348
Copy link
Assignees
oowekyala
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.36.0

Description

@ajeans
ajeans
opened on May 25, 2021
Issue body actions

Affects PMD Version:

6.34.0

Description:

We started adding java 16 records and PMD is generating a stacktrace when analyzing a source file containing a record.

Caused by: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0

Exception Stacktrace:

java.lang.RuntimeException: net.sourceforge.pmd.PMDException: Error while processing n/a
	at net.sourceforge.pmd.testframework.RuleTst.runTestFromString(RuleTst.java:300)
	at net.sourceforge.pmd.testframework.RuleTst.runTestFromString(RuleTst.java:305)
	at net.sourceforge.pmd.testframework.RuleTst.processUsingStringReader(RuleTst.java:257)
	at net.sourceforge.pmd.testframework.RuleTst.runTest(RuleTst.java:148)
	at net.sourceforge.pmd.testframework.RuleTestRunner$2.evaluate(RuleTestRunner.java:117)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at net.sourceforge.pmd.testframework.RuleTestRunner.runChild(RuleTestRunner.java:102)
	at net.sourceforge.pmd.testframework.RuleTestRunner.runChild(RuleTestRunner.java:36)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at net.sourceforge.pmd.testframework.PMDTestRunner.run(PMDTestRunner.java:97)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
	at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:188)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:154)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:128)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)
Caused by: net.sourceforge.pmd.PMDException: Error while processing n/a
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:119)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:95)
	at net.sourceforge.pmd.testframework.RuleTst.runTestFromString(RuleTst.java:298)
	... 42 more
Caused by: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:359)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at net.sourceforge.pmd.lang.java.rule.errorprone.ConstructorCallsOverridableMethodRule.getCurrentEvalPackage(ConstructorCallsOverridableMethodRule.java:627)
	at net.sourceforge.pmd.lang.java.rule.errorprone.ConstructorCallsOverridableMethodRule.visit(ConstructorCallsOverridableMethodRule.java:940)
	at net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration.jjtAccept(ASTMethodDeclaration.java:37)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:267)
	at net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration.jjtAccept(ASTClassOrInterfaceBodyDeclaration.java:44)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:862)
	at net.sourceforge.pmd.lang.java.ast.ASTRecordBody.jjtAccept(ASTRecordBody.java:31)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:847)
	at net.sourceforge.pmd.lang.java.ast.ASTRecordDeclaration.jjtAccept(ASTRecordDeclaration.java:40)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:417)
	at net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration.jjtAccept(ASTTypeDeclaration.java:39)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220)
	at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:392)
	at net.sourceforge.pmd.lang.java.rule.errorprone.ConstructorCallsOverridableMethodRule.visit(ConstructorCallsOverridableMethodRule.java:855)
	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.RuleSet.apply(RuleSet.java:659)
	at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:163)
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:200)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:113)

Code Sample demonstrating the issue:

record HelloMsg(String msg) {

  HelloMsg toTheWorld() {
    return new HelloMsg("World");
  }

  String hello() {
    return "Hello " + msg;
  }
}

Steps to reproduce:

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

I reproduced by adding a test case in the PMD project (easier to reproduce this way)

  1. Add the following test code to pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/ConstructorCallsOverridableMethod.xml
    <test-code>
        <description>Record creates an IndexOutOfBounds exception</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
record HelloMsg(String msg) {

  HelloMsg toTheWorld() {
    return new HelloMsg("World");
  }

  String hello() {
    return "Hello " + msg;
  }
}
        ]]></code>
    </test-code>
  1. Run the unit test with ./mvnw -pl pmd-java test -Dtest=ConstructorCallsOverridableMethodTest

  2. Observe that the test fails with the following message and the stracktrace shared above.

[ERROR] net.sourceforge.pmd.lang.java.rule.errorprone.ConstructorCallsOverridableMethodTest  Time elapsed: 0.034 s  <<< ERROR!
java.lang.RuntimeException: "Record creates an IndexOutOfBounds exception" failed
Caused by: java.lang.RuntimeException: net.sourceforge.pmd.PMDException: Error while processing n/a
Caused by: net.sourceforge.pmd.PMDException: Error while processing n/a
Caused by: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0

Activity

  1. ajeans
    added
    a:bugPMD crashes or fails to analyse a file.
    on May 25, 2021
  2. oowekyala
    changed the title [-]java.lang.IndexOutOfBoundsException on a java16 record[/-] [+][java] ConstructorCallsOverridableMethodRule IndexOutOfBoundsException on a java16 record[/+] on May 25, 2021
  3. pbilstein commented on Jun 21, 2021

    @pbilstein
    pbilstein
    on Jun 21, 2021
    More actions

    Same problem here with PMD check via Gradle

    Reacted by Jon Rosner
  4. oowekyala
    self-assigned this
    on Jun 21, 2021
  5. oowekyala
    added this to the 6.36.0 milestone on Jun 21, 2021
  6. oowekyala
    added a commit that references this issue on Jun 21, 2021

    Fix pmd#3305 - NPE with records

    This issue will close once commit 26c0b48 is merged into the 'main' branch.
    26c0b48
  7. adangel
    added 2 commits that reference this issue on Jun 24, 2021

    [doc] Update release notes (pmd#3305, pmd#3348)

    39484c4

    Merge pull request pmd#3348 from oowekyala:issue3305-ioob-record

    1e1fcf5
  8. adangel
    closed this as completedin #3348on Jun 24, 2021
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.

Type

No type

Projects

No projects

    Milestone

    • 6.36.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.