classloaders: Java class loaders module (three built-in loaders and which modules each owns, parent delegation traced across a two-loader chain, child-first PluginLoader, class identity and the failing (Plugin) cast, Class.forName vs loadClass initialisation, ClassNotFoundException vs NoClassDefFoundError incl. 'Could not initialize class', hot reload, unloading and a Registry leak, context class loader, jcmd VM.classloaders), 18 contract tests

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b5pUjAyJuUaNEQqzGJ
This commit is contained in:
Ankur
2026-11-25 13:17:24 +05:30
co-authored by Claude Sonnet 5.5
parent 74da9cd899
commit cca173d104
37 changed files with 1151 additions and 0 deletions
@@ -0,0 +1,13 @@
package com.acme.initfail;
import com.ankurm.classloaders.api.Plugin;
/** The class file is present and valid. Its static initialiser throws. */
public class Broken implements Plugin {
static final int LIMIT = Integer.parseInt("not-a-number");
@Override
public String run() {
return "never reached " + LIMIT;
}
}
@@ -0,0 +1,8 @@
package com.acme.shared;
/** A "shared library" class that lives in a different directory (a different loader) than its user. */
public class Lib {
public String name() {
return "Lib";
}
}
@@ -0,0 +1,7 @@
package com.acme.missing;
public class Dep {
public String hello() {
return "Dep is here";
}
}
@@ -0,0 +1,11 @@
package com.acme.missing;
import com.ankurm.classloaders.api.Plugin;
/** Compiles fine against Dep. The demo then deletes Dep.class before running it. */
public class Holder implements Plugin {
@Override
public String run() {
return new Dep().hello();
}
}
@@ -0,0 +1,9 @@
package com.acme;
public class Noisy {
static {
System.out.println(" >> Noisy static initialiser ran");
}
public static void touch() {}
}
@@ -0,0 +1,11 @@
package com.acme;
import com.acme.shared.Lib;
import com.ankurm.classloaders.api.Plugin;
public class UsesLib implements Plugin {
@Override
public String run() {
return "UsesLib called " + new Lib().name(); // forces a second class load, of Lib
}
}
@@ -0,0 +1,10 @@
package com.acme;
import com.ankurm.classloaders.api.Plugin;
public class GreeterPlugin implements Plugin {
@Override
public String run() {
return "Hello from GreeterPlugin v1";
}
}
@@ -0,0 +1,10 @@
package com.acme;
import com.ankurm.classloaders.api.Plugin;
public class GreeterPlugin implements Plugin {
@Override
public String run() {
return "Hello from GreeterPlugin v2";
}
}