From 7b608ab99502fa91d4c5efa40c9709b30623185a Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 8 Aug 2018 13:23:51 +0200 Subject: [PATCH] Ensure AnnotationUtilsTests pass in Eclipse again --- .../core/annotation/AnnotationUtilsTests.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java index 918f2e8dbb..51fc3ea0d3 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java @@ -23,6 +23,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -145,7 +146,16 @@ public class AnnotationUtilsTests { assertNull(getAnnotation(bridgeMethod, Order.class)); assertNotNull(findAnnotation(bridgeMethod, Order.class)); - assertNotNull(bridgeMethod.getAnnotation(Transactional.class)); + boolean runningInEclipse = Arrays.stream(new Exception().getStackTrace()) + .anyMatch(element -> element.getClassName().startsWith("org.eclipse.jdt")); + + // As of JDK 8, invoking getAnnotation() on a bridge method actually finds an + // annotation on its 'bridged' method; however, the Eclipse compiler still does + // not properly support this. Thus, we effectively ignore the following assertion + // if the test is currently executing within the Eclipse IDE. + if (!runningInEclipse) { + assertNotNull(bridgeMethod.getAnnotation(Transactional.class)); + } assertNotNull(getAnnotation(bridgeMethod, Transactional.class)); assertNotNull(findAnnotation(bridgeMethod, Transactional.class)); }