fix ClassCastException in
org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(Method, Object, Object...)
This commit is contained in:
@@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -32,7 +32,6 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -1205,7 +1204,7 @@ public class ReflectiveInterceptor {
|
|||||||
if (target instanceof Constructor) {
|
if (target instanceof Constructor) {
|
||||||
return jlrConstructorGetAnnotation((Constructor) target, (Class) params[0]);
|
return jlrConstructorGetAnnotation((Constructor) target, (Class) params[0]);
|
||||||
} else if (target instanceof Method) {
|
} else if (target instanceof Method) {
|
||||||
return jlClassGetAnnotation((Class) target, (Class) params[0]);
|
return jlrMethodGetAnnotation((Method) target, (Class) params[0]);
|
||||||
} else if (target instanceof Field) {
|
} else if (target instanceof Field) {
|
||||||
return jlrFieldGetAnnotation((Field) target, (Class) params[0]);
|
return jlrFieldGetAnnotation((Field) target, (Class) params[0]);
|
||||||
}
|
}
|
||||||
@@ -1241,7 +1240,7 @@ public class ReflectiveInterceptor {
|
|||||||
if (target instanceof Constructor) {
|
if (target instanceof Constructor) {
|
||||||
return jlrConstructorGetAnnotation((Constructor) target, (Class) params[0]);
|
return jlrConstructorGetAnnotation((Constructor) target, (Class) params[0]);
|
||||||
} else if (target instanceof Method) {
|
} else if (target instanceof Method) {
|
||||||
return jlClassGetAnnotation((Class) target, (Class) params[0]);
|
return jlrMethodGetAnnotation((Method) target, (Class) params[0]);
|
||||||
} else if (target instanceof Field) {
|
} else if (target instanceof Field) {
|
||||||
return jlrFieldGetAnnotation((Field) target, (Class) params[0]);
|
return jlrFieldGetAnnotation((Field) target, (Class) params[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -551,6 +551,30 @@ public class ReflectiveReflectionTests extends SpringLoadedTests {
|
|||||||
result = runUnguarded(rtype.getClazz(), "run");
|
result = runUnguarded(rtype.getClazz(), "run");
|
||||||
assertEquals("null @java.lang.Deprecated()", result.returnValue);
|
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
|
// general
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user