git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@330 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -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> |
@@ -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()); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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; |