Consistent catching of Throwable for introspection failures
Issue: SPR-12889
(cherry picked from commit 0186809)
This commit is contained in:
parent
cbc512f3be
commit
17f7f1fc15
|
|
@ -151,7 +151,7 @@ public class AnnotatedElementUtils {
|
|||
*/
|
||||
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) {
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
return getMetaAnnotationTypes(element, element.getAnnotation(annotationType));
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ public class AnnotatedElementUtils {
|
|||
*/
|
||||
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType) {
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
return hasMetaAnnotationTypes(element, annotationType, null);
|
||||
}
|
||||
|
|
@ -266,7 +266,7 @@ public class AnnotatedElementUtils {
|
|||
*/
|
||||
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) {
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
// Shortcut: directly present on the element, with no processing needed?
|
||||
if (element.isAnnotationPresent(annotationType)) {
|
||||
|
|
@ -333,7 +333,7 @@ public class AnnotatedElementUtils {
|
|||
public static AnnotationAttributes getMergedAnnotationAttributes(
|
||||
AnnotatedElement element, Class<? extends Annotation> annotationType) {
|
||||
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
AnnotationAttributes attributes = searchWithGetSemantics(element, annotationType, null,
|
||||
new MergedAnnotationAttributesProcessor());
|
||||
AnnotationUtils.postProcessAnnotationAttributes(element, attributes, false, false);
|
||||
|
|
@ -417,7 +417,7 @@ public class AnnotatedElementUtils {
|
|||
* @see AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement)
|
||||
*/
|
||||
public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement element, Class<A> annotationType) {
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
// Shortcut: directly present on the element, with no merging needed?
|
||||
if (!(element instanceof Class)) {
|
||||
|
|
@ -458,7 +458,7 @@ public class AnnotatedElementUtils {
|
|||
Class<A> annotationType) {
|
||||
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true);
|
||||
searchWithGetSemantics(element, annotationType, null, processor);
|
||||
|
|
@ -525,7 +525,7 @@ public class AnnotatedElementUtils {
|
|||
Class<A> annotationType, Class<? extends Annotation> containerType) {
|
||||
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
if (containerType == null) {
|
||||
containerType = resolveContainerType(annotationType);
|
||||
|
|
@ -611,7 +611,7 @@ public class AnnotatedElementUtils {
|
|||
*/
|
||||
public static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType) {
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
// Shortcut: directly present on the element, with no processing needed?
|
||||
if (element.isAnnotationPresent(annotationType)) {
|
||||
|
|
@ -714,7 +714,7 @@ public class AnnotatedElementUtils {
|
|||
* @see #getMergedAnnotationAttributes(AnnotatedElement, Class)
|
||||
*/
|
||||
public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) {
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
// Shortcut: directly present on the element, with no merging needed?
|
||||
if (!(element instanceof Class)) {
|
||||
|
|
@ -783,7 +783,7 @@ public class AnnotatedElementUtils {
|
|||
Class<A> annotationType) {
|
||||
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
MergedAnnotationAttributesProcessor processor = new MergedAnnotationAttributesProcessor(false, false, true);
|
||||
searchWithFindSemantics(element, annotationType, null, processor);
|
||||
|
|
@ -850,7 +850,7 @@ public class AnnotatedElementUtils {
|
|||
Class<A> annotationType, Class<? extends Annotation> containerType) {
|
||||
|
||||
Assert.notNull(element, "AnnotatedElement must not be null");
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
|
||||
if (containerType == null) {
|
||||
containerType = resolveContainerType(annotationType);
|
||||
|
|
@ -957,7 +957,7 @@ public class AnnotatedElementUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
AnnotationUtils.handleIntrospectionFailure(element, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -1246,7 +1246,7 @@ public class AnnotatedElementUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
AnnotationUtils.handleIntrospectionFailure(element, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -1288,7 +1288,7 @@ public class AnnotatedElementUtils {
|
|||
try {
|
||||
return (A[]) AnnotationUtils.getValue(container);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
AnnotationUtils.handleIntrospectionFailure(element, ex);
|
||||
}
|
||||
// Unable to read value from repeating annotation container -> ignore it.
|
||||
|
|
@ -1307,8 +1307,8 @@ public class AnnotatedElementUtils {
|
|||
Class<? extends Annotation> containerType = AnnotationUtils.resolveContainerAnnotationType(annotationType);
|
||||
if (containerType == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"annotationType must be a repeatable annotation: failed to resolve container type for "
|
||||
+ annotationType.getName());
|
||||
"Annotation type must be a repeatable annotation: failed to resolve container type for " +
|
||||
annotationType.getName());
|
||||
}
|
||||
return containerType;
|
||||
}
|
||||
|
|
@ -1330,15 +1330,15 @@ public class AnnotatedElementUtils {
|
|||
Class<?> returnType = method.getReturnType();
|
||||
if (!returnType.isArray() || returnType.getComponentType() != annotationType) {
|
||||
String msg = String.format(
|
||||
"Container type [%s] must declare a 'value' attribute for an array of type [%s]",
|
||||
containerType.getName(), annotationType.getName());
|
||||
"Container type [%s] must declare a 'value' attribute for an array of type [%s]",
|
||||
containerType.getName(), annotationType.getName());
|
||||
throw new AnnotationConfigurationException(msg);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
AnnotationUtils.rethrowAnnotationConfigurationException(ex);
|
||||
String msg = String.format("Invalid declaration of container type [%s] for repeatable annotation [%s]",
|
||||
containerType.getName(), annotationType.getName());
|
||||
containerType.getName(), annotationType.getName());
|
||||
throw new AnnotationConfigurationException(msg, ex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ public abstract class AnnotationUtils {
|
|||
try {
|
||||
return synthesizeAnnotation(annotatedElement.getAnnotation(annotationType), annotatedElement);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(annotatedElement, ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -190,7 +190,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
return synthesizeAnnotation(annotation, annotatedElement);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(annotatedElement, ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -230,7 +230,7 @@ public abstract class AnnotationUtils {
|
|||
try {
|
||||
return synthesizeAnnotationArray(annotatedElement.getAnnotations(), annotatedElement);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(annotatedElement, ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -252,7 +252,7 @@ public abstract class AnnotationUtils {
|
|||
try {
|
||||
return synthesizeAnnotationArray(BridgeMethodResolver.findBridgedMethod(method).getAnnotations(), method);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(method, ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -471,7 +471,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
return new AnnotationCollector<A>(annotationType, containerAnnotationType, declaredMode).getResult(annotatedElement);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(annotatedElement, ex);
|
||||
}
|
||||
return Collections.emptySet();
|
||||
|
|
@ -534,7 +534,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(annotatedElement, ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -633,7 +633,7 @@ public abstract class AnnotationUtils {
|
|||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(ifcMethod, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -723,7 +723,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(clazz, ex);
|
||||
return null;
|
||||
}
|
||||
|
|
@ -840,7 +840,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(clazz, ex);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -903,12 +903,11 @@ public abstract class AnnotationUtils {
|
|||
/**
|
||||
* Determine if the supplied {@link Annotation} is defined in the core JDK
|
||||
* {@code java.lang.annotation} package.
|
||||
* @param annotation the annotation to check (never {@code null})
|
||||
* @param annotation the annotation to check
|
||||
* @return {@code true} if the annotation is in the {@code java.lang.annotation} package
|
||||
*/
|
||||
public static boolean isInJavaLangAnnotationPackage(Annotation annotation) {
|
||||
Assert.notNull(annotation, "Annotation must not be null");
|
||||
return isInJavaLangAnnotationPackage(annotation.annotationType().getName());
|
||||
return (annotation != null && isInJavaLangAnnotationPackage(annotation.annotationType().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -919,8 +918,7 @@ public abstract class AnnotationUtils {
|
|||
* @since 4.2
|
||||
*/
|
||||
public static boolean isInJavaLangAnnotationPackage(String annotationType) {
|
||||
Assert.hasText(annotationType, "annotationType must not be null or empty");
|
||||
return annotationType.startsWith("java.lang.annotation");
|
||||
return (annotationType != null && annotationType.startsWith("java.lang.annotation"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1077,7 +1075,7 @@ public abstract class AnnotationUtils {
|
|||
attributes.put(method.getName(),
|
||||
adaptValue(annotatedElement, attributeValue, classValuesAsString, nestedAnnotationsAsMap));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
if (ex instanceof InvocationTargetException) {
|
||||
Throwable targetException = ((InvocationTargetException) ex).getTargetException();
|
||||
rethrowAnnotationConfigurationException(targetException);
|
||||
|
|
@ -1492,7 +1490,7 @@ public abstract class AnnotationUtils {
|
|||
public static <A extends Annotation> A synthesizeAnnotation(Map<String, Object> attributes,
|
||||
Class<A> annotationType, AnnotatedElement annotatedElement) {
|
||||
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
if (attributes == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -1572,7 +1570,7 @@ public abstract class AnnotationUtils {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <A extends Annotation> A[] synthesizeAnnotationArray(Map<String, Object>[] maps, Class<A> annotationType) {
|
||||
Assert.notNull(annotationType, "annotationType must not be null");
|
||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||
if (maps == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -1850,7 +1848,7 @@ public abstract class AnnotationUtils {
|
|||
* @param ex the exception that we encountered
|
||||
* @see #rethrowAnnotationConfigurationException
|
||||
*/
|
||||
static void handleIntrospectionFailure(AnnotatedElement element, Exception ex) {
|
||||
static void handleIntrospectionFailure(AnnotatedElement element, Throwable ex) {
|
||||
rethrowAnnotationConfigurationException(ex);
|
||||
|
||||
Log loggerToUse = logger;
|
||||
|
|
@ -1962,7 +1960,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(element, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -1977,7 +1975,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
return synthesizedAnnotations;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
handleIntrospectionFailure(element, ex);
|
||||
}
|
||||
// Unable to read value from repeating annotation container -> ignore it.
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ public class ComposedRepeatableAnnotationsTests {
|
|||
|
||||
private void expectNonRepeatableAnnotation() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(startsWith("annotationType must be a repeatable annotation"));
|
||||
exception.expectMessage(startsWith("Annotation type must be a repeatable annotation"));
|
||||
exception.expectMessage(containsString("failed to resolve container type for"));
|
||||
exception.expectMessage(containsString(NonRepeatable.class.getName()));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue