I have a javaagent that prints out names of all classes that get loaded, and their source (where they are from).
public byte[] transform(ClassLoader loader, String className, Class redefiningClass, ProtectionDomain domain, byte[] bytes) throws IllegalClassFormatException {
System.out.print("Loading class: " + className + "\t");
if (domain != null) {
final CodeSource cs = domain.getCodeSource();
if (cs != null) {
System.out.println(cs.getLocation());
}
}
System.out.println();
return bytes;
}
For some classes, it prints out “null” (meaning cs.getLocation() is null). Why is this, and is there anyway to see where those classes are from? Note, I am not doing this on my own Java app, so I have no knowledge of any custom ClassLoaders it uses.
According to Jetty 7.0.0RC4, it appears a
nullCodeSourcereflects that the class has global permissions.This behavior is documented in the specification of
ClassLoader.defineClass, so it isn’t arbitrary 😉Actually, looking closer, I believe this is the work of
SecureClassLoader.defineClass…