diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2007-06-02 14:12:36 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2007-06-02 14:12:36 +0000 |
commit | b8445cabacd7ab2a9c04bc5936583060f35ef505 (patch) | |
tree | 0d3ed708d5c2ef0b2849e45b44d1ec3e250062a5 /src/main/javassist/bytecode/ClassFile.java | |
parent | 8242ef42ef19f1f6a3f15e9b230f0317067f3863 (diff) | |
download | javassist-b8445cabacd7ab2a9c04bc5936583060f35ef505.tar.gz javassist-b8445cabacd7ab2a9c04bc5936583060f35ef505.zip |
fixed bugs related to stack map tables.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@378 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode/ClassFile.java')
-rw-r--r-- | src/main/javassist/bytecode/ClassFile.java | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java index 3d743d7b..73cdc6ec 100644 --- a/src/main/javassist/bytecode/ClassFile.java +++ b/src/main/javassist/bytecode/ClassFile.java @@ -46,10 +46,28 @@ public final class ClassFile { String cachedSuperclass; /** + * The major version number of class files + * for JDK 1.3. + */ + public static final int JAVA_3 = 47; + + /** + * The major version number of class files + * for JDK 1.5. + */ + public static final int JAVA_5 = 49; + + /** + * The major version number of class files + * for JDK 1.6. + */ + public static final int JAVA_6 = 50; + + /** * The major version number of class files created * from scratch. The value is 47 (JDK 1.3). */ - public static final int MAJOR_VERSION = 47; + public static final int MAJOR_VERSION = JAVA_3; /** * Constructs a class file from a byte stream. @@ -540,6 +558,8 @@ public final class ClassFile { /** * Appends a method to the class. + * If there is a bridge method with the same name and signature, + * then the bridge method is removed before a new method is added. * * @throws DuplicateMemberException when the method is already included. */ @@ -558,20 +578,38 @@ public final class ClassFile { String name = newMinfo.getName(); String descriptor = newMinfo.getDescriptor(); ListIterator it = methods.listIterator(0); - while (it.hasNext()) { - MethodInfo minfo = (MethodInfo)it.next(); - if (minfo.getName().equals(name) - && notBridgeMethod(minfo) && notBridgeMethod(newMinfo) - && Descriptor.eqParamTypes(minfo.getDescriptor(), - descriptor)) + while (it.hasNext()) + if (isDuplicated(newMinfo, name, descriptor, (MethodInfo)it.next(), it)) throw new DuplicateMemberException("duplicate method: " + name - + " in " + this.getName()); + + " in " + this.getName()); + } + + private static boolean isDuplicated(MethodInfo newMethod, String newName, + String newDesc, MethodInfo minfo, + ListIterator it) + { + if (!minfo.getName().equals(newName)) + return false; + + String desc = minfo.getDescriptor(); + if (!Descriptor.eqParamTypes(desc, newDesc)) + return false; + + if (desc.equals(newDesc)) { + if (notBridgeMethod(minfo)) + return true; + else { + it.remove(); + return false; + } } + else + return notBridgeMethod(minfo) && notBridgeMethod(newMethod); } /* For a bridge method, see Sec. 15.12.4.5 of JLS 3rd Ed. */ - private boolean notBridgeMethod(MethodInfo minfo) { + private static boolean notBridgeMethod(MethodInfo minfo) { return (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0; } |