!include once #1019934 // BCEL import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.SourceFile; import org.apache.bcel.generic.*; static void renameSourceInfoInClassFile(File classFile, S newName) { JavaClass c = new ClassParser(classFile.getPath(), classFile.getName()).parse(); //print(c.getSourceFileName()); ClassGen g = new ClassGen(c); int nameIndex = g.getConstantPool().addUtf8(newName); for (Attribute attr : g.getAttributes()) if (attr instanceof SourceFile) { g.removeAttribute(attr); break; } g.addAttribute(new SourceFile( g.getConstantPool().addUtf8("SourceFile"), 2, nameIndex, g.getConstantPool().getConstantPool())); c = g.getJavaClass(); c.dump(classFile); // overwrite! }