Repository navigation
Closed
Description
Affects PMD Version:
7.1.0
Description:
Parsing failed in ParseLock#doParse()
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 2
Exception Stacktrace:
[ERROR] Parsing failed in ParseLock#doParse()
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 2
at jdk.internal.util.Preconditions.outOfBounds (Preconditions.java:64)
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex (Preconditions.java:70)
at jdk.internal.util.Preconditions.checkIndex (Preconditions.java:266)
at java.util.Objects.checkIndex (Objects.java:361)
at java.util.ArrayList.get (ArrayList.java:427)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeAnnotationHelper.handleEnclosingType (TypeAnnotationHelper.java:157)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeAnnotationHelper.resolvePathStep (TypeAnnotationHelper.java:100)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeAnnotationHelper.applySinglePath (TypeAnnotationHelper.java:95)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase$LazyMethodType.acceptAnnotationAfterParse (GenericSigBase.java:351)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeAnnotationHelper$TypeAnnotationSetWithReferences.forEach (TypeAnnotationHelper.java:72)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase$LazyMethodType.doParse (GenericSigBase.java:256)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase$1.doParse (GenericSigBase.java:54)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.ParseLock.getFinalStatus (ParseLock.java:33)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.ParseLock.ensureParsed (ParseLock.java:22)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase.ensureParsed (GenericSigBase.java:76)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase.getTypeParams (GenericSigBase.java:92)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.ExecutableStub.getTypeParameters (ExecutableStub.java:60)
at net.sourceforge.pmd.lang.java.types.ClassMethodSigImpl.getTypeParameters (ClassMethodSigImpl.java:127)
at net.sourceforge.pmd.lang.java.types.JMethodSig.isGeneric (JMethodSig.java:161)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.isPotentiallyApplicable (Infer.java:989)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.computeCompileTimeDecl (Infer.java:277)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.getCompileTimeDecl (Infer.java:254)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:187)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:176)
at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
at net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver.handlePoly (LazyTypeResolver.java:267)
at net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver.visit (LazyTypeResolver.java:272)
at net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver.visit (LazyTypeResolver.java:95)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.acceptVisitor (ASTMethodCall.java:75)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode.getTypeMirror (AbstractJavaTypeNode.java:51)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.getTypeMirror (ASTMethodCall.java:22)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode.getTypeMirror (AbstractJavaTypeNode.java:39)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.getTypeMirror (ASTMethodCall.java:22)
at net.sourceforge.pmd.lang.java.ast.InternalApiBridge.lambda$forceTypeResolutionPhase$0 (InternalApiBridge.java:86)
at java.util.Iterator.forEachRemaining (Iterator.java:133)
at net.sourceforge.pmd.lang.ast.internal.IteratorBasedNStream.forEach (IteratorBasedNStream.java:102)
at net.sourceforge.pmd.lang.java.ast.InternalApiBridge.forceTypeResolutionPhase (InternalApiBridge.java:84)
at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.lambda$process$3 (JavaAstProcessor.java:134)
at net.sourceforge.pmd.benchmark.TimeTracker.bench (TimeTracker.java:163)
at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.process (JavaAstProcessor.java:134)
at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.process (JavaAstProcessor.java:164)
at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.process (JavaAstProcessor.java:148)
at net.sourceforge.pmd.lang.java.ast.JavaParser.parseImpl (JavaParser.java:69)
at net.sourceforge.pmd.lang.java.ast.JavaParser.parseImpl (JavaParser.java:25)
at net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter.parse (JjtreeParserAdapter.java:36)
at net.sourceforge.pmd.lang.impl.PmdRunnable.parse (PmdRunnable.java:112)
at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource (PmdRunnable.java:132)
at net.sourceforge.pmd.lang.impl.PmdRunnable.run (PmdRunnable.java:80)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:539)
at java.util.concurrent.FutureTask.run (FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
at java.lang.Thread.run (Thread.java:840)
Code Sample demonstrating the issue:
This is happening in a large commercial project with many source files. PMD does not give any hints about which file failed to parse, so I don't know how to even begin minimizing the issue. If there is some flag I can enable that will cause PMD to output more information, I'd be happy to spend time putting together a minimal test case.
Steps to reproduce:
See note above---I cannot (yet) provide a minimal reproduction.
mvn clean install
Running PMD through: Maven
MacOS 14.3.1
OpenJDK 17.0.10
Maven-pmd-plugin 3.22.0 using <targetJdk>17</targetJdk>
Activity
likeabantha commentedon May 25, 2024
@Calvin-L - Right, we need some data/ testcase to reproduce this scenario.
https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/TypeAnnotationHelper.java#L156
selectedTypeIndex value is -1 'cause, enclosingTypes.size() & selectionDepth both these values are coming as 2
and getting -1th index from list is causing IndexOutOfBoundsException
oowekyala commentedon May 25, 2024
Can you run maven with the
-Xflag to enable debug output?Calvin-L commentedon May 26, 2024
@oowekyala
-Xshows a few warnings likeand
but these may be red herrings; many different files show up in the output but only one
IndexOutOfBoundsExceptionexception gets thrown. Also, other modules in this project have similar warnings without anyIndexOutOfBoundsExceptionexception.(I am on vacation until 6/10, and I plan to investigate further when I get back.)
Calvin-L commentedon Jun 11, 2024
I haven't had much success minimizing the issue. It seems incredibly brittle; seemingly-irrelevant changes to the source files cause the exception to disappear on me.
As best I can tell, the problem involves
The IndexOutOfBounds exception is thrown when invoking PMD on a file that looks like
where
Cls1(which is compiled and available on PMD's--aux-classpath) hasDebugging PMD itself, the failing call to
handleEnclosingTypeis givent = pkg.Cls1#Innerpath = .i = 0annot = NonNullPerhaps the bug is that the
whileloop does not checkpath.getLength? The docs don't say anything about whatpath.getStep()should return when the argument is out of bounds, and in my debugging I observed thatpath.getLength() == 1path.getStep(0) == TypePath.INNER_TYPEpath.getStep(1) == TypePath.INNER_TYPE<-- weird, but it's an out-of-bounds read, so I guess anything is legal outputBecause of what
path.getStep(1)returns, the loop continues incrementingselectionDepthhigher than it should. Should the loop condition includei + selectionDepth < path.getLength()?kelunik commentedon Jul 13, 2026
@Calvin-L Claude built a nice reproduction case for this, see #6866.
[java] fix: IndexOutOfBoundsException for type annotations on inner c…