Skip to content

GROOVY-12206: Ingest type-use annotations when reading compiled classes - #2743

Open
paulk-asert wants to merge 1 commit into
apache:masterfrom
paulk-asert:groovy12206
Open

GROOVY-12206: Ingest type-use annotations when reading compiled classes#2743
paulk-asert wants to merge 1 commit into
apache:masterfrom
paulk-asert:groovy12206

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses GROOVY-12206 by ensuring Groovy ingests type-use (JSR 308) annotations—including those stored in bytecode “type annotation” attributes—when building AST metadata from compiled classes (both via reflection/VMPlugin and via ASM decompilation). This enables nullness/type-checking features (e.g., NullChecker) to reliably observe libraries like JSpecify, whose annotations are TYPE_USE-only.

Changes:

  • Extend NullChecker to recognize nullness annotations present on the declared type (type-use annotations) in addition to declaration annotations.
  • Implement recursive ingestion of reflective AnnotatedType structures in Java8 (and reuse in Java16) so type-use annotations on generics/arrays/wildcards/supertypes/throws/type params are applied to ClassNode/GenericsType without mutating shared cached nodes.
  • Enhance ASM decompiler stubs and parsing so bytecode type annotations are captured with position (TypeReference + TypePath) and attached to the correct AST type locations; add tests for both reflection and decompiler paths plus a JSpecify precompiled fixture and documentation updates.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
subprojects/groovy-typecheckers/src/test/groovy/groovy/typecheckers/support/JSpecifyExample.java Adds a precompiled Java fixture using JSpecify TYPE_USE nullness annotations for regression coverage.
subprojects/groovy-typecheckers/src/test/groovy/groovy/typecheckers/NullCheckerTest.groovy Adds tests verifying NullChecker observes type-use nullness from compiled Java classes on the classpath.
subprojects/groovy-typecheckers/src/spec/doc/typecheckers.adoc Documents recognition of declaration + type-use nullness annotations, including from compiled classes.
subprojects/groovy-typecheckers/src/main/groovy/groovy/typecheckers/NullChecker.groovy Extends annotation detection to consider ClassNode.typeAnnotations for methods/params/fields.
src/test/groovy/org/codehaus/groovy/ast/decompiled/support/WhereAnno.java Introduces a runtime-retained type-use annotation used to validate ingestion and exact positioning.
src/test/groovy/org/codehaus/groovy/ast/decompiled/ReflectionTypeAnnotationsTest.groovy Adds tests for the reflection/VMPlugin path ingesting AnnotatedType type-use annotations.
src/test/groovy/org/codehaus/groovy/ast/decompiled/AsmDecompilerTestData.java Adds a richer fixture class (MoreTypeAnnotations) exercising generics/arrays/wildcards/throws/type params.
src/test/groovy/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy Adds ASM decompiler path tests validating correct attachment of type-use annotations and non-mutation of shared nodes.
src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java Applies reflective type-use annotations recursively to ClassNode trees (generics/arrays/wildcards/supertypes/throws/type params).
src/main/java/org/codehaus/groovy/vmplugin/v16/Java16.java Reuses the new reflective annotation application for record component types.
src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java Applies bytecode type annotations (with position) to fields/method return/params/throws/type params during member reconstruction.
src/main/java/org/codehaus/groovy/ast/decompiled/ClassStub.java Extends stubs to store type annotations with typeRef + typePath and unifies member/record-component handling.
src/main/java/org/codehaus/groovy/ast/decompiled/ClassSignatureParser.java Applies class-level type annotations to superclass/interfaces/type parameters and record component types.
src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java Captures bytecode type annotations (class/member/field/record component) into stubs with positional metadata.
src/main/java/org/codehaus/groovy/ast/decompiled/Annotations.java Implements position-aware application of bytecode type annotations via TypeReference + TypePath walking.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.27160% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.8855%. Comparing base (023b9f5) to head (7e103e6).

Files with missing lines Patch % Lines
...rg/codehaus/groovy/ast/decompiled/Annotations.java 82.0000% 2 Missing and 7 partials ⚠️
...in/java/org/codehaus/groovy/vmplugin/v8/Java8.java 87.5000% 3 Missing and 5 partials ⚠️
.../org/codehaus/groovy/ast/decompiled/ClassStub.java 88.8889% 1 Missing ⚠️
...main/groovy/groovy/typecheckers/NullChecker.groovy 90.0000% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2743        +/-   ##
==================================================
+ Coverage     69.8687%   69.8855%   +0.0169%     
- Complexity      35137      35190        +53     
==================================================
  Files            1554       1554                
  Lines          130731     130864       +133     
  Branches        23916      23955        +39     
==================================================
+ Hits            91340      91455       +115     
- Misses          31145      31154         +9     
- Partials         8246       8255         +9     
Files with missing lines Coverage Δ
.../codehaus/groovy/ast/decompiled/AsmDecompiler.java 95.8904% <100.0000%> (+0.1761%) ⬆️
...us/groovy/ast/decompiled/ClassSignatureParser.java 96.6102% <100.0000%> (+0.5317%) ⬆️
...s/groovy/ast/decompiled/MemberSignatureParser.java 97.4684% <100.0000%> (+0.3669%) ⬆️
.../java/org/codehaus/groovy/vmplugin/v16/Java16.java 52.0000% <100.0000%> (ø)
.../org/codehaus/groovy/ast/decompiled/ClassStub.java 94.9152% <88.8889%> (-1.8061%) ⬇️
...main/groovy/groovy/typecheckers/NullChecker.groovy 79.3478% <90.0000%> (+3.0766%) ⬆️
...in/java/org/codehaus/groovy/vmplugin/v8/Java8.java 79.5977% <87.5000%> (+1.7030%) ⬆️
...rg/codehaus/groovy/ast/decompiled/Annotations.java 86.7257% <82.0000%> (-3.1294%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Jul 28, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 7e103e6
▶️ Tests: 99822 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

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.

3 participants