forked from jboss-javassist/javassist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters