aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/CtClassType.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2009-04-10 06:43:23 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2009-04-10 06:43:23 +0000
commite6ba542a6ee9bf5c0092406bbd5130abefcd90c8 (patch)
treeefb32c624f7c0feee69a9d100bd1f79e5937e3ad /src/main/javassist/CtClassType.java
parent8c878b45dee35c5e3d57e838513d9d4d475e9d02 (diff)
downloadjavassist-e6ba542a6ee9bf5c0092406bbd5130abefcd90c8.tar.gz
javassist-e6ba542a6ee9bf5c0092406bbd5130abefcd90c8.zip
improved the runtime check by CtClass.addMethod()
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@476 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/CtClassType.java')
-rw-r--r--src/main/javassist/CtClassType.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java
index 24735dbb..7ddee72d 100644
--- a/src/main/javassist/CtClassType.java
+++ b/src/main/javassist/CtClassType.java
@@ -1229,11 +1229,19 @@ class CtClassType extends CtClass {
public void addMethod(CtMethod m) throws CannotCompileException {
checkModify();
if (m.getDeclaringClass() != this)
- throw new CannotCompileException("cannot add");
+ throw new CannotCompileException("bad declaring class");
+
+ int mod = m.getModifiers();
+ if ((getModifiers() & Modifier.INTERFACE) != 0) {
+ m.setModifiers(mod | Modifier.PUBLIC);
+ if ((mod & Modifier.ABSTRACT) == 0)
+ throw new CannotCompileException(
+ "an interface method must be abstract: " + m.toString());
+ }
getMembers().addMethod(m);
getClassFile2().addMethod(m.getMethodInfo2());
- if ((m.getModifiers() & Modifier.ABSTRACT) != 0)
+ if ((mod & Modifier.ABSTRACT) != 0)
setModifiers(getModifiers() | Modifier.ABSTRACT);
}