Limit pack modules to the API, the JDK and their own pack

The pack class loader's parent is now ApiAndJdkClassLoader: com.volmit.
classes and resources come from the API's loader, everything else from
the platform loader, so modules no longer see Iris internals or the
libraries Iris bundles.

Before any class is defined, a pack load now fails when a jar holds a
com.volmit. class, and when a class references a class that is not in
the API, the JDK or a jar of the pack (read with java.lang.classfile).
Linkage errors while installing name the module's jar. ModuleInfo names
and versions reject line breaks and other control characters.
This commit is contained in:
piexel committed 2026-10-05 18:24:53 +02:00
1 parent 862f4d19be
commit 1553959cf4
11 files changed
+563 -60

No files matched your search

@@ -0,0 +1,48 @@
package com.volmit.host;
import com.volmit.IrisModule;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class ApiAndJdkClassLoaderTest {
private static final ClassLoader HOST = IrisModule.class.getClassLoader();
private static final String HOST_LIBRARY_SERVICE_FILE = "META-INF/services/org.junit.platform.engine.TestEngine";
private final ApiAndJdkClassLoader loader = new ApiAndJdkClassLoader(HOST);
private static String classFile(Class<?> type) {
return type.getName().replace('.', '/') + ".class";
}
@Test
void loadsApiClassesFromTheHostAndJdkClassesFromThePlatform() throws Exception {
assertSame(IrisModule.class, loader.loadClass(IrisModule.class.getName()));
assertSame(List.class, loader.loadClass(List.class.getName()));
assertSame(java.sql.Connection.class, loader.loadClass(java.sql.Connection.class.getName()));
}
@Test
void hidesHostClassesOutsideTheApi() {
assertDoesNotThrow(() -> HOST.loadClass(Test.class.getName()));
assertThrows(ClassNotFoundException.class, () -> loader.loadClass(Test.class.getName()));
}
@Test
void resourcesFollowTheSameRuleAsClasses() throws Exception {
assertNotNull(loader.getResource(classFile(IrisModule.class)));
assertNotNull(loader.getResource(classFile(List.class)));
assertNull(loader.getResource(classFile(Test.class)));
assertFalse(Collections.list(HOST.getResources(HOST_LIBRARY_SERVICE_FILE)).isEmpty());
assertTrue(Collections.list(loader.getResources(HOST_LIBRARY_SERVICE_FILE)).isEmpty());
}
@Test
void knowsWhichClassesItHasWithoutLoadingThem() {
assertTrue(loader.hasClass(IrisModule.class.getName()));
assertTrue(loader.hasClass("java.lang.String"));
assertFalse(loader.hasClass(Test.class.getName()));
assertFalse(loader.hasClass("com.volmit.DoesNotExist"));
}
}