aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2006-11-07 04:19:37 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2006-11-07 04:19:37 +0000
commit1a24a3971de663bd7c7e303eab5bbaafe03b327e (patch)
tree96adb06228c9df14f8783c1a44f9fb61f9af16af
parent56af2ace49d2ea3778fa8fb12621117cd4b272f4 (diff)
downloadjavassist-1a24a3971de663bd7c7e303eab5bbaafe03b327e.tar.gz
javassist-1a24a3971de663bd7c7e303eab5bbaafe03b327e.zip
Fixed a bug of duplicating writeReplace() to a proxy class.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@330 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r--Readme.html3
-rw-r--r--src/main/javassist/bytecode/ClassFile.java16
-rw-r--r--src/main/javassist/bytecode/DuplicateMemberException.java30
-rw-r--r--src/main/javassist/util/proxy/ProxyFactory.java7
4 files changed, 48 insertions, 8 deletions
diff --git a/Readme.html b/Readme.html
index ce7eb953..20945b60 100644
--- a/Readme.html
+++ b/Readme.html
@@ -704,7 +704,8 @@ Howard Lewis Ship, Richard Jones, Marjan Sterjev,
Bruce McDonald, Mark Brennan, Vlad Skarzhevskyy,
Brett Randall, Tsuyoshi Murakami, Nathan Meyers, Yoshiyuki Usui
Yutaka Sunaga, Arjan van der Meer, Bruce Eckel, Guillaume Pothier,
-Kumar Matcha, Andreas Salathe, Renat Zubairov, Armin Haaf
+Kumar Matcha, Andreas Salathe, Renat Zubairov, Armin Haaf,
+Emmanuel Bernard
and all other contributors for their contributions.
<p><br>
diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java
index 5dbc19a0..013b533e 100644
--- a/src/main/javassist/bytecode/ClassFile.java
+++ b/src/main/javassist/bytecode/ClassFile.java
@@ -465,8 +465,10 @@ public final class ClassFile {
/**
* Appends a field to the class.
+ *
+ * @throws DuplicateMemberException when the field is already included.
*/
- public void addField(FieldInfo finfo) throws CannotCompileException {
+ public void addField(FieldInfo finfo) throws DuplicateMemberException {
testExistingField(finfo.getName(), finfo.getDescriptor());
fields.add(finfo);
}
@@ -476,12 +478,12 @@ public final class ClassFile {
}
private void testExistingField(String name, String descriptor)
- throws CannotCompileException {
+ throws DuplicateMemberException {
ListIterator it = fields.listIterator(0);
while (it.hasNext()) {
FieldInfo minfo = (FieldInfo)it.next();
if (minfo.getName().equals(name))
- throw new CannotCompileException("duplicate field: " + name);
+ throw new DuplicateMemberException("duplicate field: " + name);
}
}
@@ -523,8 +525,10 @@ public final class ClassFile {
/**
* Appends a method to the class.
+ *
+ * @throws DuplicateMemberException when the method is already included.
*/
- public void addMethod(MethodInfo minfo) throws CannotCompileException {
+ public void addMethod(MethodInfo minfo) throws DuplicateMemberException {
testExistingMethod(minfo);
methods.add(minfo);
}
@@ -534,7 +538,7 @@ public final class ClassFile {
}
private void testExistingMethod(MethodInfo newMinfo)
- throws CannotCompileException
+ throws DuplicateMemberException
{
String name = newMinfo.getName();
String descriptor = newMinfo.getDescriptor();
@@ -545,7 +549,7 @@ public final class ClassFile {
&& notBridgeMethod(minfo) && notBridgeMethod(newMinfo)
&& Descriptor.eqParamTypes(minfo.getDescriptor(),
descriptor))
- throw new CannotCompileException("duplicate method: " + name
+ throw new DuplicateMemberException("duplicate method: " + name
+ " in " + this.getName());
}
}
diff --git a/src/main/javassist/bytecode/DuplicateMemberException.java b/src/main/javassist/bytecode/DuplicateMemberException.java
new file mode 100644
index 00000000..7946615d
--- /dev/null
+++ b/src/main/javassist/bytecode/DuplicateMemberException.java
@@ -0,0 +1,30 @@
+/*
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2006 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;
+
+import javassist.CannotCompileException;
+
+/**
+ * An exception thrown when adding a duplicate member is requested.
+ *
+ * @see ClassFile#addMethod(MethodInfo)
+ * @see ClassFile#addField(FieldInfo)
+ */
+public class DuplicateMemberException extends CannotCompileException {
+ public DuplicateMemberException(String msg) {
+ super(msg);
+ }
+}
diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java
index 444697ec..252dda3d 100644
--- a/src/main/javassist/util/proxy/ProxyFactory.java
+++ b/src/main/javassist/util/proxy/ProxyFactory.java
@@ -512,7 +512,12 @@ public class ProxyFactory {
addMethodsHolder(cf, pool, classname, s);
addSetter(classname, cf, pool);
- cf.addMethod(makeWriteReplace(pool));
+ try {
+ cf.addMethod(makeWriteReplace(pool));
+ }
+ catch (DuplicateMemberException e) {
+ // writeReplace() is already declared in the super class/interfaces.
+ }
thisClass = null;
return cf;