From: chiba Date: Tue, 29 Aug 2006 08:39:32 +0000 (+0000) Subject: minor bug fixes X-Git-Tag: rel_3_17_1_ga~315 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a0860e0b8c1c9b755dca9083b568354028619a9a;p=javassist.git minor bug fixes git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@319 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/ClassMap.java b/src/main/javassist/ClassMap.java index 916dee5e..95aa757d 100644 --- a/src/main/javassist/ClassMap.java +++ b/src/main/javassist/ClassMap.java @@ -61,12 +61,21 @@ public class ClassMap extends java.util.HashMap { /** * Maps a class name to another name in this hashtable. + * If the hashtable contains another mapping from the same + * class name, the old mapping is replaced. * This method translates the given class names into the * internal form used in the JVM before putting it in * the hashtable. * + *

If oldname is equivalent to + * newname, then this method does not + * perform anything; it does not record the mapping from + * oldname to newname. See + * fix method. + * * @param oldname the original class name * @param newname the substituted class name. + * @see #fix(String) */ public void put(String oldname, String newname) { if (oldname == newname) @@ -78,6 +87,33 @@ public class ClassMap extends java.util.HashMap { super.put(oldname2, toJvmName(newname)); } + /** + * Maps a class name to another name unless another mapping + * has been already recorded. + * This method translates the given class names into the + * internal form used in the JVM before putting it in + * the hashtable. + * + *

If oldname is equivalent to + * newname, then this method does not + * perform anything; it does not record the mapping from + * oldname to newname. See + * fix method. + * + * @param oldname the original class name + * @param newname the substituted class name. + * @see #fix(String) + */ + public void add(String oldname, String newname) { + if (oldname == newname) + return; + + String oldname2 = toJvmName(oldname); + String s = (String)get(oldname2); + if (s == null) + super.put(oldname2, toJvmName(newname)); + } + protected final void put0(Object oldname, Object newname) { super.put(oldname, newname); } diff --git a/src/main/javassist/CtBehavior.java b/src/main/javassist/CtBehavior.java index 9be97eba..d01773b2 100644 --- a/src/main/javassist/CtBehavior.java +++ b/src/main/javassist/CtBehavior.java @@ -47,18 +47,20 @@ public abstract class CtBehavior extends CtMember { if (map == null) map = new ClassMap(); - map.put(srcClass.getName(), declaring.getName()); + map.add(srcClass.getName(), declaring.getName()); try { boolean patch = false; CtClass srcSuper = srcClass.getSuperclass(); - String destSuperName = declaring.getSuperclass().getName(); - if (srcSuper != null) { + CtClass destSuper = declaring.getSuperclass(); + String destSuperName = null; + if (srcSuper != null && destSuper != null) { String srcSuperName = srcSuper.getName(); + destSuperName = destSuper.getName(); if (!srcSuperName.equals(destSuperName)) if (srcSuperName.equals(CtClass.javaLangObject)) patch = true; else - map.put(srcSuperName, destSuperName); + map.add(srcSuperName, destSuperName); } methodInfo = new MethodInfo(cp, srcInfo.getName(), srcInfo, map);