aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/javassist/CtClassType.java7
-rw-r--r--src/main/javassist/bytecode/analysis/ControlFlow.java9
-rw-r--r--src/test/javassist/JvstTest3.java3
-rw-r--r--src/test/javassist/JvstTest5.java16
4 files changed, 29 insertions, 6 deletions
diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java
index 627c15cf..29aace81 100644
--- a/src/main/javassist/CtClassType.java
+++ b/src/main/javassist/CtClassType.java
@@ -1400,10 +1400,11 @@ class CtClassType extends CtClass {
int mod = m.getModifiers();
if ((getModifiers() & Modifier.INTERFACE) != 0) {
- m.setModifiers(mod | Modifier.PUBLIC);
- if ((mod & Modifier.ABSTRACT) == 0)
+ if (Modifier.isProtected(mod) || Modifier.isPrivate(mod))
throw new CannotCompileException(
- "an interface method must be abstract: " + m.toString());
+ "an interface method must be public: " + m.toString());
+
+ m.setModifiers(mod | Modifier.PUBLIC);
}
getMembers().addMethod(m);
diff --git a/src/main/javassist/bytecode/analysis/ControlFlow.java b/src/main/javassist/bytecode/analysis/ControlFlow.java
index 736299cb..0bf76a3d 100644
--- a/src/main/javassist/bytecode/analysis/ControlFlow.java
+++ b/src/main/javassist/bytecode/analysis/ControlFlow.java
@@ -71,6 +71,8 @@ public class ControlFlow {
return new Block[size];
}
}.make(minfo);
+ if (basicBlocks == null)
+ basicBlocks = new Block[0];
int size = basicBlocks.length;
int[] counters = new int[size];
for (int i = 0; i < size; i++) {
@@ -97,6 +99,9 @@ public class ControlFlow {
/**
* Returns all the basic blocks in the method body.
+ *
+ * @return an array of basic blocks, the array has length 0 if
+ * the method doesn't have code.
*/
public Block[] basicBlocks() {
return basicBlocks;
@@ -133,7 +138,7 @@ public class ControlFlow {
* For every array element <code>node</code>, its index in the
* array is equivalent to <code>node.block().index()</code>.
*
- * @return an array of the tree nodes, or null if the method is abstract.
+ * @return an array of the tree nodes, or null if the method doesn't have code.
* @see Node#block()
* @see Block#index()
*/
@@ -179,7 +184,7 @@ public class ControlFlow {
* For every array element <code>node</code>, its index in the
* array is equivalent to <code>node.block().index()</code>.
*
- * @return an array of the tree nodes, or null if the method is abstract.
+ * @return an array of the tree nodes, or null if the method doesn't have code.
* @see Node#block()
* @see Block#index()
*/
diff --git a/src/test/javassist/JvstTest3.java b/src/test/javassist/JvstTest3.java
index d99fde1f..427479d1 100644
--- a/src/test/javassist/JvstTest3.java
+++ b/src/test/javassist/JvstTest3.java
@@ -1086,7 +1086,8 @@ public class JvstTest3 extends JvstTestRoot {
CtMethod m3 = CtMethod.make("public void foo3() {}", cc);
try {
cc.addMethod(m3);
- fail();
+ if (ClassFile.MAJOR_VERSION < ClassFile.JAVA_8)
+ fail();
}
catch (CannotCompileException e) {
// System.out.println(e);
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index 792fed6e..779df525 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -235,4 +235,20 @@ public class JvstTest5 extends JvstTestRoot {
Object obj = make(ctClass.getName());
assertEquals(1, invoke(obj, "run"));
}
+
+ public void testAddDefaultMethod() throws Exception {
+ CtClass cc = sloader.makeInterface("test5.AddDefaultMethod");
+ cc.addMethod(CtNewMethod.make("static int foo() { return 1; }", cc));
+ cc.addMethod(CtNewMethod.make("public static int foo1() { return 1; }", cc));
+ cc.addMethod(CtNewMethod.make("public int foo2() { return 1; }", cc));
+ cc.addMethod(CtNewMethod.make("int foo3() { return 1; }", cc));
+ try {
+ cc.addMethod(CtNewMethod.make("private int foo4() { return 1; }", cc));
+ fail();
+ } catch (CannotCompileException e) {}
+ try {
+ cc.addMethod(CtNewMethod.make("private static int foo5() { return 1; }", cc));
+ fail();
+ } catch (CannotCompileException e) {}
+ }
}