Skip to content

[java] Fix #5041: IndexOutOfBoundsException for type annotations on inner class method signatures - #6866

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
kelunik:issue-5041
Jul 16, 2026
Merged

UncleOwen merged 4 commits into
pmd:mainfrom
kelunik:issue-5041

Conversation

@kelunik

@kelunik kelunik commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

The while-loop in handleEnclosingType() was missing a bounds check on the TypePath length. ASM's TypePath.getStep(i) does pure array arithmetic with no bounds check of its own.

When the loop consumed the last valid INNER_TYPE step and called getStep one past the end, it read the high byte of the following type_index field (the CP index of the annotation type).

That byte equals 1 (= INNER_TYPE) when the CP index is in [256, 511], so the loop over-incremented selectionDepth and crashed on enclosingTypes.get(-1).

The regression test uses TestClass, which has 300 dummy fields to push the Ann descriptor past CP index 255, reliably reproducing the crash.

Related issues

Fixes #5041.

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

The while-loop in handleEnclosingType() was missing a bounds check on
the TypePath length. ASM's TypePath.getStep(i) does pure array
arithmetic with no bounds check of its own.

When the loop consumed the last valid INNER_TYPE step and called getStep
one past the end, it read the high byte of the following type_index
field (the CP index of the annotation type).

That byte equals 1 (= INNER_TYPE) when the CP index is in [256, 511], so
the loop over-incremented selectionDepth and crashed on
enclosingTypes.get(-1).

The regression test uses TestClass, which has 300 dummy fields to push
the Ann descriptor past CP index 255, reliably reproducing the crash.

Fixes pmd#5041.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@pmd-actions-helper

pmd-actions-helper Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-07-16 15:03:16+00:00 for e949b60)

@UncleOwen UncleOwen changed the title [java] fix: IOOBE for type annotations on inner class method signatures [java] fix: IndexOutOfBoundsException for type annotations on inner class method signatures Jul 16, 2026
@UncleOwen
UncleOwen merged commit 609dd4e into pmd:main Jul 16, 2026
13 checks passed
@UncleOwen UncleOwen added this to the 7.27.0 milestone Jul 16, 2026
@kelunik
kelunik deleted the issue-5041 branch July 16, 2026 16:03
@Calvin-L

Copy link
Copy Markdown

Thanks @kelunik @zbynek @UncleOwen. I'm pleased to see this fixed. :)

@adangel adangel changed the title [java] fix: IndexOutOfBoundsException for type annotations on inner class method signatures [java] Fix #5041: IndexOutOfBoundsException for type annotations on inner class method signatures Jul 17, 2026
@kelunik

kelunik commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@UncleOwen will there be a delayed July release or will the July release be skipped until end of August?

@UncleOwen

Copy link
Copy Markdown
Member

See #6896

@kelunik

kelunik commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Unfortunate, but thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] Parsing failed in ParseLock#doParse(): IndexOutOfBoundsException

4 participants