mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
add DefineClass to test suite
As reported on the discussion group, there is a problem with the ClassLoader.defineClass implementation sunch that this test is not currently passing, at least for the mode=debug and bootimage=true builds. I plan to address these failures soon, but I wanted to add a test first to make sure I could reproduce them.
This commit is contained in:
parent
69dc2026a1
commit
ff18524906
52
test/DefineClass.java
Normal file
52
test/DefineClass.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
|
||||||
|
public class DefineClass {
|
||||||
|
private static File findHello(File directory) {
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
for (File file: directory.listFiles()) {
|
||||||
|
if (file.isFile()) {
|
||||||
|
if (file.getName().equals("Hello.class")) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
} else if (file.isDirectory()) {
|
||||||
|
File result = findHello(file);
|
||||||
|
if (result != null) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] read(File file) throws IOException {
|
||||||
|
byte[] bytes = new byte[(int) file.length()];
|
||||||
|
FileInputStream in = new FileInputStream(file);
|
||||||
|
try {
|
||||||
|
if (in.read(bytes) != (int) file.length()) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
} finally {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
byte[] bytes = read(findHello(new File(System.getProperty("user.dir"))));
|
||||||
|
Class c = new MyClassLoader(DefineClass.class.getClassLoader()).defineClass
|
||||||
|
("Hello", bytes);
|
||||||
|
c.getMethod("main", String[].class).invoke(null, (Object) new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyClassLoader extends ClassLoader {
|
||||||
|
public MyClassLoader(ClassLoader parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class defineClass(String name, byte[] bytes) {
|
||||||
|
return super.defineClass(name, bytes, 0, bytes.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user