Document that annotations which reference types not present are ignored

Add warnings to the class-level Javadoc for MergedAnnotations,
AnnotatedTypeMetadata, AnnotationMetadata, and MethodMetadata to point
out that annotations may be ignored if their attributes reference types
that are not present in the classpath.

Closes gh-35959
This commit is contained in:
Sam Brannen 2025-12-05 15:49:13 +01:00
parent 87d0113b25
commit b916dc962e
4 changed files with 36 additions and 4 deletions

View File

@ -133,6 +133,14 @@ import org.springframework.util.Assert;
* please use standard Java reflection or Spring's {@link AnnotationUtils}
* for simple annotation retrieval purposes.
*
* <p><strong>WARNING</strong>: If an annotation cannot be loaded because one of
* its attributes references a {@link Class} or {@link Enum}
* {@linkplain TypeNotPresentException that is not present in the classpath}, that
* annotation will not be accessible via the {@code MergedAnnotations} API.
* To assist with diagnosing such scenarios, you can set the log level for
* {@code "org.springframework.core.annotation.MergedAnnotation"} to {@code DEBUG},
* {@code INFO}, or {@code WARN}.
* @author Phillip Webb
* @author Sam Brannen
* @since 5.2

View File

@ -37,11 +37,19 @@ import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.util.MultiValueMap;
/**
* Defines access to the annotations of a specific type ({@link AnnotationMetadata class}
* or {@link MethodMetadata method}), in a form that does not necessarily require
* Defines access to the annotations on a specific {@link AnnotationMetadata class}
* or {@link MethodMetadata method}, in a form that does not necessarily require
* class loading of the types being inspected. Note, however, that classes for
* encountered annotations will be loaded.
*
* <p><strong>WARNING</strong>: If an annotation cannot be loaded because one of
* its attributes references a {@link Class} or {@link Enum}
* {@linkplain TypeNotPresentException that is not present in the classpath}, that
* annotation will not be accessible via the {@code AnnotatedTypeMetadata} API.
* To assist with diagnosing such scenarios, you can set the log level for
* {@code "org.springframework.core.annotation.MergedAnnotation"} to {@code DEBUG},
* {@code INFO}, or {@code WARN}.
*
* @author Juergen Hoeller
* @author Mark Fisher
* @author Mark Pollack

View File

@ -25,9 +25,17 @@ import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
/**
* Interface that defines abstract access to the annotations of a specific
* Interface that defines abstract access to the annotations on a specific
* class, in a form that does not require that class to be loaded yet.
*
* <p><strong>WARNING</strong>: If an annotation cannot be loaded because one of
* its attributes references a {@link Class} or {@link Enum}
* {@linkplain TypeNotPresentException that is not present in the classpath}, that
* annotation will not be accessible via the {@code AnnotationMetadata} API.
* To assist with diagnosing such scenarios, you can set the log level for
* {@code "org.springframework.core.annotation.MergedAnnotation"} to {@code DEBUG},
* {@code INFO}, or {@code WARN}.
*
* @author Juergen Hoeller
* @author Mark Fisher
* @author Phillip Webb

View File

@ -19,9 +19,17 @@ package org.springframework.core.type;
import java.lang.reflect.Method;
/**
* Interface that defines abstract access to the annotations of a specific
* Interface that defines abstract access to the annotations on a specific
* method, in a form that does not require that method's class to be loaded yet.
*
* <p><strong>WARNING</strong>: If an annotation cannot be loaded because one of
* its attributes references a {@link Class} or {@link Enum}
* {@linkplain TypeNotPresentException that is not present in the classpath},
* that annotation will not be accessible via the {@code MethodMetadata} API.
* To assist with diagnosing such scenarios, you can set the log level for
* {@code "org.springframework.core.annotation.MergedAnnotation"} to {@code DEBUG},
* {@code INFO}, or {@code WARN}.
*
* @author Juergen Hoeller
* @author Mark Pollack
* @author Chris Beams