Skip to content

Detect annotation usage in Java classfile analysis (fixes #146)#1722

Open
jozanek wants to merge 1 commit into
sbt:developfrom
jozanek:fix/issue-146-param-annotations
Open

Detect annotation usage in Java classfile analysis (fixes #146)#1722
jozanek wants to merge 1 commit into
sbt:developfrom
jozanek:fix/issue-146-param-annotations

Conversation

@jozanek

@jozanek jozanek commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #146.

Extends the Java classfile parser to extract annotation references from all classfile locations, not just RuntimeVisible/InvisibleAnnotations on classes/fields/methods:

Location JVMS
Parameter annotations 4.7.18
Type annotations (field/return/supertype/…) 4.7.20
Type annotations on locals/casts (nested in Code) 4.7.3
Annotations on record components (nested in Record) 4.7.30
Types referenced by an @interface element default 4.7.22

Details

  • Shared core, distinct entry parsers. parseAnnotation/parseElementValue are shared; each attribute shape gets a thin entry parser. Type annotations skip the target_info/type_path prefix before the body.
  • Nested recursion. Code and Record attributes are descended into; readNestedAttributes materializes only annotation-bearing sub-attributes and skips the rest in-stream.
  • Correct class-literal decoding. class element values (possibly arrays [Lpkg/Foo; or primitives) are decoded via descriptorToTypes instead of string-slicing.
  • Robustness. The "warn, don't fail" guard is widened to NonFatal, since nested parsing can surface EOFException on malformed input.

Out of scope: RetentionPolicy.SOURCE annotations are erased by javac and never appear in classfiles — undetectable by design.

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.

Usage of annotations not detected by javac analysis

1 participant