diff options
author | Johan Kaving <johan.kaving@symsoft.com> | 2014-07-02 16:45:46 +0200 |
---|---|---|
committer | Johan Kaving <johan.kaving@symsoft.com> | 2014-07-03 15:49:59 +0200 |
commit | b510f4c43b12a283294718e906a7502958f71cd6 (patch) | |
tree | 058dc10f3cbf0abaf95445812851970cae6b3e7a /src | |
parent | c499faf6a8579cdfd266a22c2d5ef491d3bea6cb (diff) | |
download | javassist-b510f4c43b12a283294718e906a7502958f71cd6.tar.gz javassist-b510f4c43b12a283294718e906a7502958f71cd6.zip |
Fix JASSIST-220
Static methods on interfaces in Java 8 means
that the INVOKESTATIC opcode can sometimes refer
to an item that is an InterfaceMethodrefInfo
(instead of a MethodrefInfo).
This is now handled in the
ConstPool.getMethodref...() methods by casting
to MemberrefInfo instead (since MemberrefInfo
contains all the needed information).
Diffstat (limited to 'src')
-rw-r--r-- | src/main/javassist/bytecode/ConstPool.java | 25 | ||||
-rw-r--r-- | src/test/javassist/JvstTest4.java | 16 | ||||
-rw-r--r-- | src/test/test4/JIRA220.java | 17 |
3 files changed, 43 insertions, 15 deletions
diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java index f1024216..f05dfd4f 100644 --- a/src/main/javassist/bytecode/ConstPool.java +++ b/src/main/javassist/bytecode/ConstPool.java @@ -389,7 +389,7 @@ public final class ConstPool { * at the given index. */ public int getMethodrefClass(int index) { - MethodrefInfo minfo = (MethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); return minfo.classIndex; } @@ -401,7 +401,7 @@ public final class ConstPool { * @return the name of the class at that <code>class_index</code>. */ public String getMethodrefClassName(int index) { - MethodrefInfo minfo = (MethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); if (minfo == null) return null; else @@ -414,7 +414,7 @@ public final class ConstPool { * at the given index. */ public int getMethodrefNameAndType(int index) { - MethodrefInfo minfo = (MethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); return minfo.nameAndTypeIndex; } @@ -427,7 +427,7 @@ public final class ConstPool { * @return the name of the method. */ public String getMethodrefName(int index) { - MethodrefInfo minfo = (MethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); if (minfo == null) return null; else { @@ -449,7 +449,7 @@ public final class ConstPool { * @return the descriptor of the method. */ public String getMethodrefType(int index) { - MethodrefInfo minfo = (MethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); if (minfo == null) return null; else { @@ -468,8 +468,7 @@ public final class ConstPool { * at the given index. */ public int getInterfaceMethodrefClass(int index) { - InterfaceMethodrefInfo minfo - = (InterfaceMethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); return minfo.classIndex; } @@ -481,8 +480,7 @@ public final class ConstPool { * @return the name of the class at that <code>class_index</code>. */ public String getInterfaceMethodrefClassName(int index) { - InterfaceMethodrefInfo minfo - = (InterfaceMethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); return getClassInfo(minfo.classIndex); } @@ -492,8 +490,7 @@ public final class ConstPool { * at the given index. */ public int getInterfaceMethodrefNameAndType(int index) { - InterfaceMethodrefInfo minfo - = (InterfaceMethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); return minfo.nameAndTypeIndex; } @@ -507,8 +504,7 @@ public final class ConstPool { * @return the name of the method. */ public String getInterfaceMethodrefName(int index) { - InterfaceMethodrefInfo minfo - = (InterfaceMethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); if (minfo == null) return null; else { @@ -531,8 +527,7 @@ public final class ConstPool { * @return the descriptor of the method. */ public String getInterfaceMethodrefType(int index) { - InterfaceMethodrefInfo minfo - = (InterfaceMethodrefInfo)getItem(index); + MemberrefInfo minfo = (MemberrefInfo)getItem(index); if (minfo == null) return null; else { diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index f8994cd7..6ea33308 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -980,4 +980,20 @@ public class JvstTest4 extends JvstTestRoot { assertEquals("i", cp.getUtf8Info(attr.name(0))); assertEquals("s", cp.getUtf8Info(attr.name(1))); } + + // JIRA JASSIST-220 + public void testStaticInterfaceMethods() throws Exception { + CtClass cc = sloader.get("test4.JIRA220"); + + cc.getMethod("foo", "()V").instrument(new ExprEditor() { + @Override + public void edit(MethodCall m) throws CannotCompileException { + try { + m.getClassName(); + } catch (Exception e) { + fail(e.getMessage()); + } + } + }); + } } diff --git a/src/test/test4/JIRA220.java b/src/test/test4/JIRA220.java new file mode 100644 index 00000000..27574278 --- /dev/null +++ b/src/test/test4/JIRA220.java @@ -0,0 +1,17 @@ +package test4; + + +import java.util.function.IntConsumer; +import java.util.stream.IntStream; + +interface JIRA220intf { + static void bar() { + // Do something + } +} + +public class JIRA220 implements JIRA220intf { + public static void foo() { + JIRA220intf.bar(); + } +} |