AnnotationUtils.java (spring-framework-5.3.23) | : | AnnotationUtils.java (spring-framework-5.3.24) | ||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | |||
* limitations under the License. | * limitations under the License. | |||
*/ | */ | |||
package org.springframework.core.annotation; | package org.springframework.core.annotation; | |||
import java.lang.annotation.Annotation; | import java.lang.annotation.Annotation; | |||
import java.lang.reflect.AnnotatedElement; | import java.lang.reflect.AnnotatedElement; | |||
import java.lang.reflect.Array; | import java.lang.reflect.Array; | |||
import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationHandler; | |||
import java.lang.reflect.Method; | import java.lang.reflect.Method; | |||
import java.lang.reflect.Modifier; | import java.lang.reflect.Modifier; | |||
import java.lang.reflect.Proxy; | ||||
import java.util.Collection; | import java.util.Collection; | |||
import java.util.Collections; | import java.util.Collections; | |||
import java.util.List; | import java.util.List; | |||
import java.util.Map; | import java.util.Map; | |||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | |||
import java.util.Set; | import java.util.Set; | |||
import org.springframework.core.BridgeMethodResolver; | import org.springframework.core.BridgeMethodResolver; | |||
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.Mirr orSet; | import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.Mirr orSet; | |||
import org.springframework.core.annotation.MergedAnnotation.Adapt; | import org.springframework.core.annotation.MergedAnnotation.Adapt; | |||
skipping to change at line 1054 | skipping to change at line 1055 | |||
* in which case such an exception will be rethrown | * in which case such an exception will be rethrown | |||
* @see #getValue(Annotation) | * @see #getValue(Annotation) | |||
*/ | */ | |||
@Nullable | @Nullable | |||
public static Object getValue(@Nullable Annotation annotation, @Nullable String attributeName) { | public static Object getValue(@Nullable Annotation annotation, @Nullable String attributeName) { | |||
if (annotation == null || !StringUtils.hasText(attributeName)) { | if (annotation == null || !StringUtils.hasText(attributeName)) { | |||
return null; | return null; | |||
} | } | |||
try { | try { | |||
Method method = annotation.annotationType().getDeclaredMe thod(attributeName); | Method method = annotation.annotationType().getDeclaredMe thod(attributeName); | |||
ReflectionUtils.makeAccessible(method); | return invokeAnnotationMethod(method, annotation); | |||
return method.invoke(annotation); | ||||
} | } | |||
catch (NoSuchMethodException ex) { | catch (NoSuchMethodException ex) { | |||
return null; | return null; | |||
} | } | |||
catch (InvocationTargetException ex) { | ||||
rethrowAnnotationConfigurationException(ex.getTargetExcep | ||||
tion()); | ||||
throw new IllegalStateException("Could not obtain value f | ||||
or annotation attribute '" + | ||||
attributeName + "' in " + annotation, ex) | ||||
; | ||||
} | ||||
catch (Throwable ex) { | catch (Throwable ex) { | |||
rethrowAnnotationConfigurationException(ex); | ||||
handleIntrospectionFailure(annotation.getClass(), ex); | handleIntrospectionFailure(annotation.getClass(), ex); | |||
return null; | return null; | |||
} | } | |||
} | } | |||
/** | /** | |||
* Invoke the supplied annotation attribute {@link Method} on the supplie | ||||
d | ||||
* {@link Annotation}. | ||||
* <p>An attempt will first be made to invoke the method via the annotati | ||||
on's | ||||
* {@link InvocationHandler} (if the annotation instance is a JDK dynamic | ||||
proxy). | ||||
* If that fails, an attempt will be made to invoke the method via reflec | ||||
tion. | ||||
* @param method the method to invoke | ||||
* @param annotation the annotation on which to invoke the method | ||||
* @return the value returned from the method invocation | ||||
* @since 5.3.24 | ||||
*/ | ||||
static Object invokeAnnotationMethod(Method method, Object annotation) { | ||||
if (Proxy.isProxyClass(annotation.getClass())) { | ||||
try { | ||||
InvocationHandler handler = Proxy.getInvocationHa | ||||
ndler(annotation); | ||||
return handler.invoke(annotation, method, null); | ||||
} | ||||
catch (Throwable ex) { | ||||
// ignore and fall back to reflection below | ||||
} | ||||
} | ||||
return ReflectionUtils.invokeMethod(method, annotation); | ||||
} | ||||
/** | ||||
* If the supplied throwable is an {@link AnnotationConfigurationExceptio n}, | * If the supplied throwable is an {@link AnnotationConfigurationExceptio n}, | |||
* it will be cast to an {@code AnnotationConfigurationException} and thr own, | * it will be cast to an {@code AnnotationConfigurationException} and thr own, | |||
* allowing it to propagate to the caller. | * allowing it to propagate to the caller. | |||
* <p>Otherwise, this method does nothing. | * <p>Otherwise, this method does nothing. | |||
* @param ex the throwable to inspect | * @param ex the throwable to inspect | |||
*/ | */ | |||
static void rethrowAnnotationConfigurationException(Throwable ex) { | static void rethrowAnnotationConfigurationException(Throwable ex) { | |||
if (ex instanceof AnnotationConfigurationException) { | if (ex instanceof AnnotationConfigurationException) { | |||
throw (AnnotationConfigurationException) ex; | throw (AnnotationConfigurationException) ex; | |||
} | } | |||
End of changes. 6 change blocks. | ||||
11 lines changed or deleted | 33 lines changed or added |