From e6ba542a6ee9bf5c0092406bbd5130abefcd90c8 Mon Sep 17 00:00:00 2001 From: chiba Date: Fri, 10 Apr 2009 06:43:23 +0000 Subject: [PATCH] improved the runtime check by CtClass.addMethod() git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@476 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/CtClassType.java | 12 ++++++++++-- 1 file 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); } -- 2.39.5