From 7f73ad1fbc637870857839969ff55f2552f3e0ea Mon Sep 17 00:00:00 2001 From: chibash Date: Fri, 21 Nov 2014 08:23:38 +0900 Subject: fixed JASSIST-237 --- src/main/javassist/ClassPool.java | 15 ++++++++++----- src/main/javassist/CtClassType.java | 15 ++++++++++++++- src/test/javassist/JvstTest4.java | 7 +++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index 0493c6db..5e006b81 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -864,14 +864,19 @@ public class ClassPool { * * @param name a fully-qualified interface name. * Or null if the annotation has no super interface. - * @param superclass the super interface. * @throws RuntimeException if the existing interface is frozen. * @since 3.19 */ - public CtClass makeAnnotation(String name, CtClass superclass) throws RuntimeException { - CtClass cc = makeInterface(name, superclass); - cc.setModifiers(cc.getModifiers() | Modifier.ANNOTATION); - return cc; + public CtClass makeAnnotation(String name) throws RuntimeException { + try { + CtClass cc = makeInterface(name, get("java.lang.annotation.Annotation")); + cc.setModifiers(cc.getModifiers() | Modifier.ANNOTATION); + return cc; + } + catch (NotFoundException e) { + // should never happen. + throw new RuntimeException(e.getMessage(), e); + } } /** diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index 7ed43759..ef3a2f77 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -676,7 +676,20 @@ class CtClassType extends CtClass { } catch (ClassNotFoundException e) { ClassLoader cl2 = cp.getClass().getClassLoader(); - return anno.toAnnotationType(cl2, cp); + try { + return anno.toAnnotationType(cl2, cp); + } + catch (ClassNotFoundException e2){ + try { + Class clazz = cp.get(anno.getTypeName()).toClass(); + return javassist.bytecode.annotation.AnnotationImpl.make( + clazz.getClassLoader(), + clazz, cp, anno); + } + catch (Throwable e3) { + throw new ClassNotFoundException(anno.getTypeName()); + } + } } } diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index 2a60af8b..d84dfbfa 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -1060,7 +1060,7 @@ public class JvstTest4 extends JvstTestRoot { } public void testAnnotationLoader() throws Exception { - CtClass anno = sloader.makeAnnotation("test4.AnnoLoadAnno", null); + CtClass anno = sloader.makeAnnotation("test4.AnnoLoadAnno"); anno.debugWriteFile(); CtClass cc = sloader.get("test4.AnnoLoad"); CtMethod m = cc.getDeclaredMethod("foo"); @@ -1073,8 +1073,7 @@ public class JvstTest4 extends JvstTestRoot { attr.setAnnotation(a); m.getMethodInfo().addAttribute(attr); cc.writeFile(); - Object obj = m.getAnnotations()[0]; - String name = obj.getClass().getName(); - assertEquals(anno.getName(), name); + Class rc = ((java.lang.annotation.Annotation)m.getAnnotations()[0]).annotationType(); + assertEquals(anno.getName(), rc.getName()); } } -- cgit v1.2.3