Avoid retaining class files in annotation metadata

ClassFileAnnotationDelegate passed the raw java.lang.classfile
Annotation to MergedAnnotation.of() as the annotation source. That
annotation holds a Utf8Entry, so retaining the metadata of an
annotated class also retained its class file byte[], the parsed
constant pool, and the class model.

Store the declaring class name instead, as the ASM variant does.

See gh-37111

Signed-off-by: Boris Perović <boris.perovic@sysdig.com>
This commit is contained in:
Boris Perović
2026-08-05 10:07:44 +02:00
committed by Brian Clozel
parent 0c281fd1ce
commit b556766e1a
@@ -76,7 +76,7 @@ abstract class ClassFileAnnotationDelegate {
}
}
Map<String, Object> compactedAttributes = (attributes.isEmpty() ? Collections.emptyMap() : attributes);
return MergedAnnotation.of(classLoader, new Source(annotation), annotationType, compactedAttributes);
return MergedAnnotation.of(classLoader, new Source(className), annotationType, compactedAttributes);
}
catch (ClassNotFoundException | LinkageError ex) {
// Non-loadable annotation type -> ignore.
@@ -146,7 +146,7 @@ abstract class ClassFileAnnotationDelegate {
}
record Source(Annotation annotation) {
record Source(String className) {
}
}