From 89c91facc0fc8fed1464f735926c2dceea692a47 Mon Sep 17 00:00:00 2001 From: chibash Date: Wed, 27 Apr 2016 23:07:26 +0900 Subject: [PATCH] fixes a bug JIRA JASSIST-262 --- Readme.html | 2 +- .../javassist/bytecode/stackmap/TypeData.java | 3 +- src/test/Test.java | 51 ++++++++++++++++--- src/test/javassist/JvstTest5.java | 25 +++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/Readme.html b/Readme.html index 181b844e..7290c099 100644 --- a/Readme.html +++ b/Readme.html @@ -283,7 +283,7 @@ see javassist.Dump.

-version 3.21

diff --git a/src/main/javassist/bytecode/stackmap/TypeData.java b/src/main/javassist/bytecode/stackmap/TypeData.java index 66199927..b83c9f69 100644 --- a/src/main/javassist/bytecode/stackmap/TypeData.java +++ b/src/main/javassist/bytecode/stackmap/TypeData.java @@ -319,11 +319,12 @@ public abstract class TypeData { } if (isBasicType) { + is2WordType = kind.is2WordType(); for (int i = 0; i < size; i++) { TypeVar cv = (TypeVar)scc.get(i); cv.lowers.clear(); cv.lowers.add(kind); - is2WordType = kind.is2WordType(); + cv.is2WordType = kind.is2WordType(); } } else { diff --git a/src/test/Test.java b/src/test/Test.java index 1aa7f8e2..441879db 100644 --- a/src/test/Test.java +++ b/src/test/Test.java @@ -1,11 +1,50 @@ import javassist.*; public class Test { - public static void main(String[] args) throws Exception { - ClassPool cp = ClassPool.getDefault(); - CtClass cc = cp.get("test5.DefaultMethod"); - CtMethod m = CtNewMethod.make("public int run(){ return test5.DefaultMethodIntf.super.foo(); }", cc); - cc.addMethod(m); - cc.writeFile(); + public static void main(String[] args) { + CtClass badClass = ClassPool.getDefault().makeClass("badClass"); + String src = String.join(System.getProperty("line.separator"), + "public void eval () {", + " if (true) {", + " double t=0;", + " } else {", + " double t=0;", + " }", + " for (int i=0; i < 2; i++) {", + " int a=0;", + " int b=0;", + " int c=0;", + " int d=0;", + " if (true) {", + " int e = 0;", + " }", + " }", + "}"); + System.out.println(src); + try { + badClass.addMethod(CtMethod.make(src, badClass)); + badClass.debugWriteFile("./bin"); + Class clazzz = badClass.toClass(); + Object obj = clazzz.newInstance(); // <-- falls here + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void eval () { + if (true) { + double t=0; + } else { + double t=0; + } + for (int i=0; i < 2; i++) { + int a=0; + int b=0; + int c=0; + int d=0; + if (true) { + int e = 0; + } + } } } diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 33740f7f..1af027fd 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -195,4 +195,29 @@ public class JvstTest5 extends JvstTestRoot { Object obj = make(cc.getName()); assertEquals(21713, invoke(obj, "run")); } + + public void testBadClass() throws Exception { + CtClass badClass = ClassPool.getDefault().makeClass("badClass"); + String src = String.join(System.getProperty("line.separator"), + "public void eval () {", + " if (true) {", + " double t=0;", + " } else {", + " double t=0;", + " }", + " for (int i=0; i < 2; i++) {", + " int a=0;", + " int b=0;", + " int c=0;", + " int d=0;", + " if (true) {", + " int e = 0;", + " }", + " }", + "}"); + System.out.println(src); + badClass.addMethod(CtMethod.make(src, badClass)); + Class clazzz = badClass.toClass(); + Object obj = clazzz.newInstance(); // <-- falls here + } } -- 2.39.5