diff --git a/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAccessibleObject.java b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAccessibleObject.java new file mode 100644 index 0000000..6d57f1c --- /dev/null +++ b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAccessibleObject.java @@ -0,0 +1,28 @@ +package iri; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Method; + +import reflection.AnnoT; + +public class JLRMGetAnnotationViaAccessibleObject extends FormattingHelper { + + @AnnoT + public void string() { + + } + + public String run() throws Exception { + Method m = AccessibleObject.class.getMethod("getAnnotation", Class.class); + Method mm = JLRMGetAnnotationViaAccessibleObject.class.getDeclaredMethod("string"); + Annotation a = (Annotation) m.invoke(mm, AnnoT.class); + Annotation b = (Annotation) m.invoke(mm, Deprecated.class); + return a + " " + b; + } + + public static void main(String[] argv) throws Exception { + System.out.println(new JLRMGetAnnotationViaAccessibleObject().run()); + } + +} diff --git a/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAccessibleObject2.java b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAccessibleObject2.java new file mode 100644 index 0000000..ddd0ff9 --- /dev/null +++ b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAccessibleObject2.java @@ -0,0 +1,33 @@ +package iri; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Method; + +import reflection.AnnoT; + +public class JLRMGetAnnotationViaAccessibleObject2 extends FormattingHelper { + + @AnnoT + public void string() { + + } + + @Deprecated + public void newmethod() { + + } + + public String run() throws Exception { + Method m = AccessibleObject.class.getMethod("getAnnotation", Class.class); + Method mm = JLRMGetAnnotationViaAccessibleObject2.class.getDeclaredMethod("newmethod"); + Annotation a = (Annotation) m.invoke(mm, AnnoT.class); + Annotation b = (Annotation) m.invoke(mm, Deprecated.class); + return a + " " + b; + } + + public static void main(String[] argv) throws Exception { + System.out.println(new JLRMGetAnnotationViaAccessibleObject2().run()); + } + +} diff --git a/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAnnotatedElement.java b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAnnotatedElement.java new file mode 100644 index 0000000..14cf1b4 --- /dev/null +++ b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAnnotatedElement.java @@ -0,0 +1,28 @@ +package iri; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; + +import reflection.AnnoT; + +public class JLRMGetAnnotationViaAnnotatedElement extends FormattingHelper { + + @AnnoT + public void string() { + + } + + public String run() throws Exception { + Method m = AnnotatedElement.class.getMethod("getAnnotation", Class.class); + Method mm = JLRMGetAnnotationViaAnnotatedElement.class.getDeclaredMethod("string"); + Annotation a = (Annotation) m.invoke(mm, AnnoT.class); + Annotation b = (Annotation) m.invoke(mm, Deprecated.class); + return a + " " + b; + } + + public static void main(String[] argv) throws Exception { + System.out.println(new JLRMGetAnnotationViaAnnotatedElement().run()); + } + +} diff --git a/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAnnotatedElement2.java b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAnnotatedElement2.java new file mode 100644 index 0000000..53e8fe5 --- /dev/null +++ b/org.springsource.loaded.testdata/src/iri/JLRMGetAnnotationViaAnnotatedElement2.java @@ -0,0 +1,33 @@ +package iri; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; + +import reflection.AnnoT; + +public class JLRMGetAnnotationViaAnnotatedElement2 extends FormattingHelper { + + @AnnoT + public void string() { + + } + + @Deprecated + public void newmethod() { + + } + + public String run() throws Exception { + Method m = AnnotatedElement.class.getMethod("getAnnotation", Class.class); + Method mm = JLRMGetAnnotationViaAnnotatedElement2.class.getDeclaredMethod("newmethod"); + Annotation a = (Annotation) m.invoke(mm, AnnoT.class); + Annotation b = (Annotation) m.invoke(mm, Deprecated.class); + return a + " " + b; + } + + public static void main(String[] argv) throws Exception { + System.out.println(new JLRMGetAnnotationViaAnnotatedElement2().run()); + } + +} diff --git a/org.springsource.loaded/src/main/java/org/springsource/loaded/ri/ReflectiveInterceptor.java b/org.springsource.loaded/src/main/java/org/springsource/loaded/ri/ReflectiveInterceptor.java index 9fbd3bf..aaa575a 100644 --- a/org.springsource.loaded/src/main/java/org/springsource/loaded/ri/ReflectiveInterceptor.java +++ b/org.springsource.loaded/src/main/java/org/springsource/loaded/ri/ReflectiveInterceptor.java @@ -32,7 +32,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.WeakHashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -1205,7 +1204,7 @@ public class ReflectiveInterceptor { if (target instanceof Constructor) { return jlrConstructorGetAnnotation((Constructor) target, (Class) params[0]); } else if (target instanceof Method) { - return jlClassGetAnnotation((Class) target, (Class) params[0]); + return jlrMethodGetAnnotation((Method) target, (Class) params[0]); } else if (target instanceof Field) { return jlrFieldGetAnnotation((Field) target, (Class) params[0]); } @@ -1241,7 +1240,7 @@ public class ReflectiveInterceptor { if (target instanceof Constructor) { return jlrConstructorGetAnnotation((Constructor) target, (Class) params[0]); } else if (target instanceof Method) { - return jlClassGetAnnotation((Class) target, (Class) params[0]); + return jlrMethodGetAnnotation((Method) target, (Class) params[0]); } else if (target instanceof Field) { return jlrFieldGetAnnotation((Field) target, (Class) params[0]); } diff --git a/org.springsource.loaded/src/test/java/org/springsource/loaded/test/ReflectiveReflectionTests.java b/org.springsource.loaded/src/test/java/org/springsource/loaded/test/ReflectiveReflectionTests.java index 4e7f203..46bc119 100644 --- a/org.springsource.loaded/src/test/java/org/springsource/loaded/test/ReflectiveReflectionTests.java +++ b/org.springsource.loaded/src/test/java/org/springsource/loaded/test/ReflectiveReflectionTests.java @@ -551,6 +551,30 @@ public class ReflectiveReflectionTests extends SpringLoadedTests { result = runUnguarded(rtype.getClazz(), "run"); assertEquals("null @java.lang.Deprecated()", result.returnValue); } + + @Test + public void testJRMethodGetAnnotationViaAccessibleObject() throws Exception { + String t = "iri.JLRMGetAnnotationViaAccessibleObject"; + TypeRegistry r = getTypeRegistry(t); + ReloadableType rtype = r.addType(t, loadBytesForClass(t)); + result = runUnguarded(rtype.getClazz(), "run"); + assertEquals("@reflection.AnnoT() null", result.returnValue); + rtype.loadNewVersion(retrieveRenameRetarget(t)); + result = runUnguarded(rtype.getClazz(), "run"); + assertEquals("null @java.lang.Deprecated()", result.returnValue); + } + + @Test + public void testGetAnnotationViaAnnotatedElement() throws Exception { + String t = "iri.JLRMGetAnnotationViaAnnotatedElement"; + TypeRegistry r = getTypeRegistry(t); + ReloadableType rtype = r.addType(t, loadBytesForClass(t)); + result = runUnguarded(rtype.getClazz(), "run"); + assertEquals("@reflection.AnnoT() null", result.returnValue); + rtype.loadNewVersion(retrieveRenameRetarget(t)); + result = runUnguarded(rtype.getClazz(), "run"); + assertEquals("null @java.lang.Deprecated()", result.returnValue); + } // general