提交 b36c9f9f 编写于 作者: S Sam Brannen

Polish introspection failure handling in AnnotationUtils

上级 23547a72
...@@ -150,10 +150,9 @@ public abstract class AnnotationUtils { ...@@ -150,10 +150,9 @@ public abstract class AnnotationUtils {
return synthesizeAnnotation(annotatedElement.getAnnotation(annotationType), annotatedElement); return synthesizeAnnotation(annotatedElement.getAnnotation(annotationType), annotatedElement);
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(annotatedElement, ex); handleIntrospectionFailure(annotatedElement, ex);
return null;
} }
return null;
} }
/** /**
...@@ -182,10 +181,9 @@ public abstract class AnnotationUtils { ...@@ -182,10 +181,9 @@ public abstract class AnnotationUtils {
return synthesizeAnnotation(annotation, annotatedElement); return synthesizeAnnotation(annotation, annotatedElement);
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(annotatedElement, ex); handleIntrospectionFailure(annotatedElement, ex);
return null;
} }
return null;
} }
/** /**
...@@ -222,7 +220,6 @@ public abstract class AnnotationUtils { ...@@ -222,7 +220,6 @@ public abstract class AnnotationUtils {
return annotatedElement.getAnnotations(); return annotatedElement.getAnnotations();
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(annotatedElement, ex); handleIntrospectionFailure(annotatedElement, ex);
} }
return null; return null;
...@@ -245,7 +242,6 @@ public abstract class AnnotationUtils { ...@@ -245,7 +242,6 @@ public abstract class AnnotationUtils {
return BridgeMethodResolver.findBridgedMethod(method).getAnnotations(); return BridgeMethodResolver.findBridgedMethod(method).getAnnotations();
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(method, ex); handleIntrospectionFailure(method, ex);
} }
return null; return null;
...@@ -301,7 +297,6 @@ public abstract class AnnotationUtils { ...@@ -301,7 +297,6 @@ public abstract class AnnotationUtils {
} }
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(annotatedElement, ex); handleIntrospectionFailure(annotatedElement, ex);
} }
return Collections.emptySet(); return Collections.emptySet();
...@@ -360,7 +355,6 @@ public abstract class AnnotationUtils { ...@@ -360,7 +355,6 @@ public abstract class AnnotationUtils {
} }
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(annotatedElement, ex); handleIntrospectionFailure(annotatedElement, ex);
} }
return null; return null;
...@@ -454,7 +448,6 @@ public abstract class AnnotationUtils { ...@@ -454,7 +448,6 @@ public abstract class AnnotationUtils {
} }
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(ifcMethod, ex); handleIntrospectionFailure(ifcMethod, ex);
} }
} }
...@@ -527,7 +520,6 @@ public abstract class AnnotationUtils { ...@@ -527,7 +520,6 @@ public abstract class AnnotationUtils {
} }
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(clazz, ex); handleIntrospectionFailure(clazz, ex);
return null; return null;
} }
...@@ -645,7 +637,6 @@ public abstract class AnnotationUtils { ...@@ -645,7 +637,6 @@ public abstract class AnnotationUtils {
} }
} }
catch (Exception ex) { catch (Exception ex) {
// Assuming nested Class values not resolvable within annotation attributes...
handleIntrospectionFailure(clazz, ex); handleIntrospectionFailure(clazz, ex);
} }
return false; return false;
...@@ -1532,8 +1523,11 @@ public abstract class AnnotationUtils { ...@@ -1532,8 +1523,11 @@ public abstract class AnnotationUtils {
* it will simply be thrown, allowing it to propagate to the caller, and * it will simply be thrown, allowing it to propagate to the caller, and
* nothing will be logged. * nothing will be logged.
* <p>Otherwise, this method logs an introspection failure (in particular * <p>Otherwise, this method logs an introspection failure (in particular
* {@code TypeNotPresentExceptions}) &mdash; before moving on, pretending * {@code TypeNotPresentExceptions}) before moving on, assuming nested
* there were no annotations on this specific element. * Class values were not resolvable within annotation attributes and
* thereby effectively pretending there were no annotations on the specified
* element.
*
* @param element the element that we tried to introspect annotations on * @param element the element that we tried to introspect annotations on
* @param ex the exception that we encountered * @param ex the exception that we encountered
* @see #rethrowAnnotationConfigurationException * @see #rethrowAnnotationConfigurationException
...@@ -1547,16 +1541,16 @@ public abstract class AnnotationUtils { ...@@ -1547,16 +1541,16 @@ public abstract class AnnotationUtils {
loggerToUse = LogFactory.getLog(AnnotationUtils.class); loggerToUse = LogFactory.getLog(AnnotationUtils.class);
logger = loggerToUse; logger = loggerToUse;
} }
if (element instanceof Class && Annotation.class.isAssignableFrom((Class<?>) element)) { if ((element instanceof Class) && Annotation.class.isAssignableFrom((Class<?>) element)) {
// Meta-annotation lookup on an annotation type // Meta-annotation lookup on an annotation type
if (logger.isDebugEnabled()) { if (loggerToUse.isDebugEnabled()) {
logger.debug("Failed to introspect meta-annotations on [" + element + "]: " + ex); loggerToUse.debug("Failed to introspect meta-annotations on [" + element + "]: " + ex);
} }
} }
else { else {
// Direct annotation lookup on regular Class, Method, Field // Direct annotation lookup on regular Class, Method, Field
if (loggerToUse.isInfoEnabled()) { if (loggerToUse.isInfoEnabled()) {
logger.info("Failed to introspect annotations on [" + element + "]: " + ex); loggerToUse.info("Failed to introspect annotations on [" + element + "]: " + ex);
} }
} }
} }
...@@ -1653,11 +1647,11 @@ public abstract class AnnotationUtils { ...@@ -1653,11 +1647,11 @@ public abstract class AnnotationUtils {
return synthesizedAnnotations; return synthesizedAnnotations;
} }
catch (Exception ex) { catch (Exception ex) {
rethrowAnnotationConfigurationException(ex); handleIntrospectionFailure(element, ex);
}
// Unable to read value from repeating annotation container -> ignore it. // Unable to read value from repeating annotation container -> ignore it.
return Collections.emptyList(); return Collections.emptyList();
} }
} }
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册