如果我打電話toBytecode()方法在我的情況下,它拋出了Javassist:toBytecode()拋出異常了java.lang.RuntimeException:remaper.by.moofMonkey.Main類被凍結,但他不結冰
java.lang.RuntimeException:remaper.by.moofMonkey.Main類被凍結在javassist.CtClassType.checkModify(CtClassType.java:515) 處於javassist.CtClass.getClassFile(CtClass.java:524) com.moofMonkey處。 Main.writeFile(Main.java:340) at com.moofMonkey.Main.saveClasses(Main.java:324) at com.moofMonkey.Main.main(Main.java:309)
我的背景:
.....
for (CtClass cl : modClasses) {
cl.stopPruning(true);
writeFile(cl, "./ModifiedClasses"); //cl.writeFile("./ModifiedClasses");
cl.stopPruning(false);
}
.....
public static void writeFile(CtClass cl, String directoryName) throws Throwable {
System.out.println(">> " + cl.getName());
byte[] bc = cl.toBytecode();
String s = cl.getClassFile().getSourceFile();
int index = new String(bc).indexOf(s);
for(int i = 0; i < s.length(); i++) //KILL SOURCEFILE (c) moofMonkey
bc[index + i] = '-';
DataOutputStream out = cl.makeFileOutput(directoryName);
out.write(bc);
out.flush();
out.close();
}
可是......可是。如果我調用writeFile()的模擬 - cl.writeFile() - 所有的作品!
我可以這樣做:
1. Save File
2. Read bytes from him
3. Dp what I need
4. Save File
Q已解決。特別感謝@SubOptimal – moofMonkey