publicstaticvoid main(String... args) throws Exception { new File("d1").mkdir(); new File("d2").mkdir();
// Step 1. build an empty class with an interface
makeClass("d1", "Empty.java", "abstract class Empty implements Readable {}");
// Step 2. Modify classfile to have invalid constant pool index
ClassFile cf = ClassFile.read(new File("d1","Empty.class"));
cf.interfaces[0] = cf.constant_pool.size() + 10;
ClassWriter cw = new ClassWriter();
cw.write(cf, new File("d2","Empty.class"));
// Step 3. Compile use of invalid class
String result = makeClass("d2", "EmptyUse.java", "class EmptyUse { Empty e; }"); if (!result.contains("compiler.misc.bad.class.file")) {
System.out.println(result); thrownew Exception("test failed");
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.