Skip to content

Conversation

@ayoube-ait
Copy link

GROOVY-11831: Fix TYPE_USE annotation crash on void method return type

Summary

Fixes a compiler crash when an annotation without explicit @Target (which defaults to all targets including TYPE_USE) is added to a void method by an AST transformation.

Error Message

BUG! exception in phase 'class generation' in source unit '...'
Adding type annotation @MyAnnotation to non-redirect node: void

Root Cause

In ExtendedVerifier.extractTypeUseAnnotations(), when processing TYPE_USE annotations on a void method, the code attempts to call addTypeAnnotations() on the void return type. Since void is a non-redirect node, this crashes.

Fix

Added a guard to skip addTypeAnnotations() for void methods only:

boolean isVoidMethod = (keepTarget == METHOD_TARGET && isPrimitiveVoid(targetType));
if (!isVoidMethod) {
    // ... add type annotations
}

The fix specifically targets void methods, not constructors (which also have void return type internally but are handled differently via GROOVY-10937).

Testing

A unit test is not included because the bug only triggers when:

  1. The annotation is pre-compiled in a separate JAR (not defined inline)
  2. An AST transformation adds that annotation to a void method

Groovy's test framework compiles everything in one stage, making it impossible to reproduce this scenario in a single test.

Manual verification: The fix is verified with a standalone reproduction project:
https://github.com/ayoube-ait/groovy-bug-repro

Impact

This bug affects Micronaut Framework's Groovy support. The @internal annotation in micronaut-core has no explicit @target and is used in AST transformations that generate void methods, preventing Groovy scripts from compiling with Micronaut 5 and Groovy 5.

@ayoube-ait ayoube-ait closed this Jan 7, 2026
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.

1 participant