Include enum array attributes in TypeNotPresentException probing - #37153
Open
junhyeong9812 wants to merge 1 commit into
Open
Include enum array attributes in TypeNotPresentException probing#37153junhyeong9812 wants to merge 1 commit into
junhyeong9812 wants to merge 1 commit into
Conversation
AttributeMethods probes Class, Class[], and enum attributes to detect annotations whose values cannot be resolved at runtime, so that such annotations are filtered during scanning instead of failing later with a raw exception. Enum array attributes were missing from the probe, allowing an annotation that references a stale enum constant to pass canLoad() and leak EnumConstantNotPresentException on later attribute access. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
junhyeong9812
force-pushed
the
fix/attributemethods-enum-array-probe
branch
from
August 19, 2026 01:33
aa2eafb to
75c0be4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
AttributeMethodsmarks attributes whose values may fail to resolve at runtime (Class,Class[], and enum types) so thatcanLoad()andvalidate()can probe them, allowing annotations that cannot be safely loaded to be filtered during scanning. Enum array attributes are missing from this check, while the adjacent nested-annotation detection already covers both the scalar and array cases.Problem
An annotation attribute of an enum array type whose bytecode references a constant that no longer exists in the enum loaded at runtime (a binary-incompatible classpath, for example partially upgraded dependencies) is not probed, so the annotation passes
canLoad():MergedAnnotationsreports the annotation as present, while a single-enum attribute in the same situation is filtered with a warning log.asMap()returns a map containing theEnumConstantNotPresentExceptioninstance as the attribute value, silently corruptingAnnotationAttributes-based consumers.getEnumArray(..)or invoking the attribute on a synthesized annotation throws a rawEnumConstantNotPresentException.The single-enum case has been covered since the check was introduced, so scalar and array attributes of the same type currently behave inconsistently.
Fix
Extend the
canThrowTypeNotPresentExceptioncomputation withtype.isArray() && type.componentType().isEnum(), mirroring the nested-annotation idiom on the adjacent line. Such annotations are now filtered during scanning exactly like their single-enum counterparts:isPresent()returnsfalsewith a warning log, and typed access follows the regular missing-annotation contract instead of leaking the raw exception.The probe adds the same kind of cost as the existing
Class[]probing, and only for enum array attributes. The scope of this change is intentionally limited to enum arrays.Tests cover the probe flag,
canLoad()andvalidate()for both the failing and the healthy case, and a non-enum array guard verifying the new condition does not widen the probe to other array types.