Skip to content

Include enum array attributes in TypeNotPresentException probing - #37153

Open
junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/attributemethods-enum-array-probe
Open

Include enum array attributes in TypeNotPresentException probing#37153
junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/attributemethods-enum-array-probe

Conversation

@junhyeong9812

Copy link
Copy Markdown
Contributor

Overview

AttributeMethods marks attributes whose values may fail to resolve at runtime (Class, Class[], and enum types) so that canLoad() and validate() 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():

  • MergedAnnotations reports the annotation as present, while a single-enum attribute in the same situation is filtered with a warning log.
  • asMap() returns a map containing the EnumConstantNotPresentException instance as the attribute value, silently corrupting AnnotationAttributes-based consumers.
  • Typed access such as getEnumArray(..) or invoking the attribute on a synthesized annotation throws a raw EnumConstantNotPresentException.

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 canThrowTypeNotPresentException computation with type.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() returns false with 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() and validate() 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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 19, 2026
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
junhyeong9812 force-pushed the fix/attributemethods-enum-array-probe branch from aa2eafb to 75c0be4 Compare August 19, 2026 01:33
@sbrannen sbrannen self-assigned this Aug 19, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants