From eada5573e0209cf24e0dfab30423de71f94e1943 Mon Sep 17 00:00:00 2001 From: chiba Date: Tue, 10 Nov 2009 10:13:37 +0000 Subject: [PATCH] improved the behavior of CtClass.getAnnotations() etc. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@503 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- .../bytecode/annotation/Annotation.java | 5 ++- .../bytecode/annotation/MemberValue.java | 9 ++++- .../bytecode/annotation/NoSuchClassError.java | 39 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/main/javassist/bytecode/annotation/NoSuchClassError.java diff --git a/src/main/javassist/bytecode/annotation/Annotation.java b/src/main/javassist/bytecode/annotation/Annotation.java index 1156a460..075b6e62 100644 --- a/src/main/javassist/bytecode/annotation/Annotation.java +++ b/src/main/javassist/bytecode/annotation/Annotation.java @@ -285,10 +285,11 @@ public class Annotation { * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation - * @throws ClassNotFoundException when the class cannot found + * @throws ClassNotFoundException if the class cannot found. + * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) - throws ClassNotFoundException + throws ClassNotFoundException, NoSuchClassError { return AnnotationImpl.make(cl, MemberValue.loadClass(cl, getTypeName()), diff --git a/src/main/javassist/bytecode/annotation/MemberValue.java b/src/main/javassist/bytecode/annotation/MemberValue.java index f2e70916..98c3e034 100644 --- a/src/main/javassist/bytecode/annotation/MemberValue.java +++ b/src/main/javassist/bytecode/annotation/MemberValue.java @@ -46,9 +46,14 @@ public abstract class MemberValue { abstract Class getType(ClassLoader cl) throws ClassNotFoundException; static Class loadClass(ClassLoader cl, String classname) - throws ClassNotFoundException + throws ClassNotFoundException, NoSuchClassError { - return Class.forName(classname, true, cl); + try { + return Class.forName(classname, true, cl); + } + catch (LinkageError e) { + throw new NoSuchClassError(classname, e); + } } /** diff --git a/src/main/javassist/bytecode/annotation/NoSuchClassError.java b/src/main/javassist/bytecode/annotation/NoSuchClassError.java new file mode 100644 index 00000000..c6d1a12f --- /dev/null +++ b/src/main/javassist/bytecode/annotation/NoSuchClassError.java @@ -0,0 +1,39 @@ +/* + * Javassist, a Java-bytecode translator toolkit. + * Copyright (C) 1999-2009 Shigeru Chiba. All Rights Reserved. + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. Alternatively, the contents of this file may be used under + * the terms of the GNU Lesser General Public License Version 2.1 or later. + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + */ + +package javassist.bytecode.annotation; + +/** + * Thrown if the linkage fails. + * It keeps the name of the class that caused this error. + */ +public class NoSuchClassError extends Error { + private String className; + + /** + * Constructs an exception. + */ + public NoSuchClassError(String className, Error cause) { + super(cause.toString(), cause); + this.className = className; + } + + /** + * Returns the name of the class not found. + */ + public String getClassName() { + return className; + } +} -- 2.39.5