Skip to content

Include enum array attributes in TypeNotPresentException probing - #37153

Merged
sbrannen merged 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/attributemethods-enum-array-probe
Oct 4, 2026
Merged

sbrannen merged 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
@sbrannen sbrannen changed the title Include enum array attributes in TypeNotPresentException probing Include enum array attributes in TypeNotPresentException probing Oct 4, 2026
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 4, 2026
@sbrannen sbrannen added this to the 7.1.0-RC1 milestone Oct 4, 2026
@sbrannen
sbrannen merged commit 9b93e5f into spring-projects:main Oct 4, 2026
4 checks passed
@sbrannen

sbrannen commented Oct 4, 2026

Copy link
Copy Markdown
Member

Good catch! 👍

This has been merged into main.

Thanks

@junhyeong9812

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for merging this.

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) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants