use of java.lang.IllegalArgumentException in project openj9 by eclipse.
the class CreateTestObjectJar method main.
public static void main(String[] args) throws Throwable {
File testDir = new File(args[0]);
String testType = args[1];
String jarFileName = null;
ClassReader cr = new ClassReader("java/lang/Object");
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
FieldVisitor fv = null;
cr.accept(cw, 0);
if (!testDir.isDirectory()) {
printUsage();
throw new IllegalArgumentException("Invalid directory: " + testDir.getPath());
}
/* Modify the Object class according with the test type */
if (testType.equalsIgnoreCase("d")) {
fv = cw.visitField(ACC_PRIVATE, "d", "D", null, null);
jarFileName = "object_d.jar";
} else if (testType.equalsIgnoreCase("i")) {
fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
jarFileName = "object_i.jar";
} else if (testType.equalsIgnoreCase("ii")) {
fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
fv = cw.visitField(ACC_PRIVATE, "ii", "I", null, null);
jarFileName = "object_ii.jar";
} else if (testType.equalsIgnoreCase("iii")) {
fv = cw.visitField(ACC_PRIVATE, "i", "I", null, null);
fv = cw.visitField(ACC_PRIVATE, "ii", "I", null, null);
fv = cw.visitField(ACC_PRIVATE, "iii", "I", null, null);
jarFileName = "object_iii.jar";
} else {
printUsage();
throw new IllegalArgumentException("Invalid test type: " + testType);
}
if (null != fv) {
fv.visitEnd();
}
/* Write the final jar file with the modified Object class in it */
if (null != jarFileName) {
ZipOutputStream outJar = new ZipOutputStream(new FileOutputStream(testDir.getPath() + "/" + jarFileName));
outJar.putNextEntry(new ZipEntry("java/lang/Object.class"));
ByteArrayInputStream inJar = new ByteArrayInputStream(cw.toByteArray());
int len;
byte[] buf = new byte[bufLen];
while ((len = inJar.read(buf)) > 0) {
outJar.write(buf, 0, len);
}
outJar.closeEntry();
outJar.close();
}
}
Aggregations