Skip to content

Commit

Permalink
fixes a bug JIRA JASSIST-262
Browse files Browse the repository at this point in the history
  • Loading branch information
chibash committed Apr 27, 2016
1 parent b110efa commit 89c91fa
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ <h2>Changes</h2>

<p>-version 3.21
<ul>
<li>JIRA JASSIST-244, 245, 248, 255, 256, 259.
<li>JIRA JASSIST-244, 245, 248, 250, 255, 256, 259, 262.
</ul>
</p>

Expand Down
3 changes: 2 additions & 1 deletion src/main/javassist/bytecode/stackmap/TypeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ private void fixTypes(ArrayList scc, ClassPool cp) throws NotFoundException {
}

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 {
Expand Down
51 changes: 45 additions & 6 deletions src/test/Test.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
25 changes: 25 additions & 0 deletions src/test/javassist/JvstTest5.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,29 @@ public void edit(MethodCall c) throws CannotCompileException {
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
}
}

0 comments on commit 89c91fa

Please sign in to comment.