/** *Mainentrypoint.
*/ publicstaticvoid main(String[] args) throws Exception { // Check the class-path for the second file. We'll use that one as the source of the // new classloader.
String cp = System.getProperty("java.class.path"); if (cp.split(System.getProperty("path.separator")).length != 1) { thrownew IllegalStateException("Didn't find exactly one classpath element in " + cp);
} if (!cp.endsWith("classloader2.jar")) { thrownew IllegalStateException("Don't understand classpath " + cp);
}
cp = cp.replace("classloader2.jar", "classloader2-ex.jar");
// Now load our test class. Class<?> srcClass = A.class; Class<?> exClass = myClassLoader.loadClass("A");
// First check: classes should be different. if (srcClass == exClass) { thrownew IllegalStateException("Loaded class instances are the same");
}
// Secondary checks: get the static field values and make sure they aren't the same.
String srcValue = (String)srcClass.getDeclaredField("value").get(null); if (!"Src-A".equals(srcValue)) { thrownew IllegalStateException("Expected Src-A, found " + srcValue);
}
String exValue = (String)exClass.getDeclaredField("value").get(null); if (!"Ex-A".equals(exValue)) { thrownew IllegalStateException("Expected Ex-A, found " + exValue);
}
// Try to load a dex file with bad dex code. Use new instance to force verification.
VerifyError existing = null; try { Class<?> badClass = Main.class.getClassLoader().loadClass("B");
System.out.println("Loaded class B.");
badClass.newInstance();
System.out.println("Should not be able to instantiate B with bad dex bytecode.");
} catch (VerifyError e) {
System.out.println("Caught VerifyError.");
existing = e;
}
// Make sure the same error is rethrown when reloading the bad class. try { Class<?> badClass = Main.class.getClassLoader().loadClass("B");
System.out.println("Loaded class B.");
badClass.newInstance();
System.out.println("Should not be able to instantiate B with bad dex bytecode.");
} catch (VerifyError e) { if (e == existing) {
System.out.println("Caught existing VerifyError.");
} else {
e.printStackTrace(System.out);
}
}
System.out.println("Everything OK.");
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-29)
¤
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.