From c0b62eeabad1f96da80f26339f6cd1986330174f Mon Sep 17 00:00:00 2001 From: chibash Date: Sun, 31 Jul 2016 12:20:22 +0900 Subject: [PATCH] modifies addInvokestatic() in Bytecode to support a static method declared in an interface type. --- src/main/javassist/bytecode/Bytecode.java | 24 ++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java index 4de69dab..34068f8d 100644 --- a/src/main/javassist/bytecode/Bytecode.java +++ b/src/main/javassist/bytecode/Bytecode.java @@ -1025,13 +1025,20 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode { * @see Descriptor#ofMethod(CtClass,CtClass[]) */ public void addInvokestatic(CtClass clazz, String name, String desc) { - addInvokestatic(constPool.addClassInfo(clazz), name, desc); + boolean isInterface; + if (clazz == THIS) + isInterface = false; + else + isInterface = clazz.isInterface(); + + addInvokestatic(constPool.addClassInfo(clazz), name, desc, isInterface); } /** * Appends INVOKESTATIC. * * @param classname the fully-qualified class name. + * It must not be an interface-type name. * @param name the method name * @param desc the descriptor of the method signature. * @@ -1045,15 +1052,26 @@ public class Bytecode extends ByteVector implements Cloneable, Opcode { * Appends INVOKESTATIC. * * @param clazz the index of CONSTANT_Class_info - * structure. + * structure. It must not be an interface type. * @param name the method name * @param desc the descriptor of the method signature. * * @see Descriptor#ofMethod(CtClass,CtClass[]) */ public void addInvokestatic(int clazz, String name, String desc) { + addInvokestatic(clazz, name, desc, false); + } + + private void addInvokestatic(int clazz, String name, String desc, + boolean isInterface) { add(INVOKESTATIC); - addIndex(constPool.addMethodrefInfo(clazz, name, desc)); + int index; + if (isInterface) + index = constPool.addInterfaceMethodrefInfo(clazz, name, desc); + else + index = constPool.addMethodrefInfo(clazz, name, desc); + + addIndex(index); growStack(Descriptor.dataSize(desc)); } -- 2.39.5