Document optional packages and the unavailable-JDK-module error

README, DESIGN and CONTRACTS describe how a module declares optional
packages in info() (with an example), that they cover only its own jar
and never excuse a load error, why missingClasses() drops excused
classes, and the new error for classes of JDK modules outside the
platform class loader, including the check order and that one error
groups every kind of unusable class.
This commit is contained in:
piexel committed 2026-10-05 21:01:34 +02:00
1 parent ec80683aa1
commit e34acf2fbb
3 files changed
+90 -24

No files matched your search

+7 -4
View File
@@ -7,7 +7,7 @@ types that carry them and lists what the Iris adapter still owes.
| Requirement | Contract |
| --- | --- |
| Module identity and composition | `IrisModule`, `ModuleInfo`, `StageGraph` |
| Module identity and composition | `IrisModule`, `ModuleInfo` (with optional packages), `StageGraph` |
| Module jars in a pack | `META-INF/services/com.volmit.IrisModule`, host `PackModules`, `DiscoveredModule`, `MissingClasses` |
| Module-owned work and ordering | `Stage`, `StageRef`, stage definitions, `requires`/`softAfter`/`softBefore` |
| Activation by configuration | `when(settingsType)`, host `ConfiguredSettings` |
@@ -30,9 +30,12 @@ context, outputs and accumulators.
Modules compile against the API `compileOnly` and never ship it. At runtime they can use the API
(`com.volmit.*`), the host packages the host chooses to expose, the JDK and the classes in their
own pack's jars. They may use any library they ship in the pack, never Iris's copy. A class Iris has
but hides, or one missing from an exposed package, fails the pack load, naming the jar and the
classes. A class nobody has (an optional dependency) only warns.
own pack's jars. They may use any library they ship in the pack, never Iris's copy. JDK modules
outside the platform class loader, such as `jdk.compiler`, are not available. A class Iris has but
hides, a class of an unavailable JDK module, or one missing from an exposed package fails the pack
load, naming the jar and the classes. A class nobody has (an optional dependency) only warns, unless
its package is one the module declares optional with `ModuleInfo.withOptionalPackages(...)`
(`PackageName`). That declaration never excuses a load error.
There is no API version gating. Packs ship their module jars, so their compatibility with the
running Iris is the pack publisher's responsibility.
+45 -7
View File
@@ -34,7 +34,7 @@ flowchart TD
## Module loading
The `IrisModule` implementation is the module's entry point. `info()` returns its id, display
name and version; there is no separate descriptor. A pack keeps its modules in
name, version and optional packages; there is no separate descriptor. A pack keeps its modules in
`<pack>/modules/*.jar`, one module per jar.
A jar names its entry class in `META-INF/services/com.volmit.IrisModule`, the provider format of
@@ -58,13 +58,16 @@ API):
ignored; zero or more than one entry class name fails.
4. Fails if a jar holds a class of an exposed package, naming the jar and the first such class.
5. Fails if a class is in two jars, naming the class and both jars.
6. Resolves every class each class uses (see below). A class that Iris has but hides, or that is
missing from an exposed package, fails the load, listing each referencing and referenced class
per jar. Classes that nobody has are collected per jar. Nothing has been defined up to here.
6. Resolves every class each class uses (see below). A class that Iris has but hides, a class of a
JDK module packs cannot see, or a class missing from an exposed package fails the load, listing
each referencing and referenced class per jar and kind. Classes that nobody has are collected
per jar. Nothing has been defined up to here.
7. Creates one `URLClassLoader` for all jars of the pack, parent = `ExposedHostClassLoader`.
8. Loads each entry class, checks that it implements `IrisModule` and comes from its own jar,
instantiates it with the public no-argument constructor and calls `info()`.
9. Logs one INFO summary of the pack's modules, and one WARNING if any classes are missing.
9. Drops each jar's missing classes that lie in the optional packages its module declares in
`info()`.
10. Logs one INFO summary of the pack's modules, and one WARNING if any missing classes remain.
One loader per pack, not per jar, because `requires(...)` takes another module's stage constant.
A pack jar that requires a stage of another pack jar must see its classes. Packs stay isolated
@@ -88,6 +91,11 @@ holds Iris internals and the libraries Iris bundles, so it is not the pack loade
to the host's loader (the loader that defines the API) and everything else to the platform class
loader, which holds the JDK. The api/host split is deferred, so `com.volmit.host` is visible too.
The platform loader provides the JDK modules defined to it and to the boot loader: `java.base`,
`java.sql`, `java.net.http`, `java.compiler` and the other standard modules. JDK modules defined to
the application loader, such as `jdk.compiler`, `jdk.jshell` and `jdk.attach`, are not available
to modules, and neither are JDK modules the runtime did not resolve.
The exposed packages (`ExposedPackages`) are the API's package, `com.volmit` (the package of
`IrisModule`), plus whatever the host passes to `PackModules.load`. The host decides those; the
intended use is the packages that hold built-in modules' stage constants, so that a pack jar can
@@ -95,7 +103,7 @@ intended use is the packages that hold built-in modules' stage constants, so tha
the host's class and the same stage constant, which resolution requires: a copy would be a second
definition of the id. Names match whole packages: `com.volmit` does not expose `com.volmitx`. A
trailing dot is accepted; anything that is not a package name, such as a blank string or a
wildcard, is rejected.
wildcard, is rejected. `PackageName` holds these rules; module optional packages use them too.
A module may use any library, but it ships that library itself, inside its own jar or as another
jar of the pack. It never borrows Iris's copy: Iris's libraries can change with any Iris update,
@@ -126,8 +134,16 @@ file, so nothing is loaded or initialized:
| --- | --- |
| in a jar of the pack, an exposed package of the host, or the JDK | resolves |
| in an exposed package, but the host does not have it | load error: the jar was built against a different Iris API or Iris version |
| in a JDK module the platform loader does not provide, such as `jdk.compiler` | load error: names the JDK module, which is not available to modules |
| not exposed, but the host's loader has it (Iris internals, Iris's copy of a library) | load error: modules cannot use Iris's classes; ship the library in the pack or use the API |
| nowhere | the pack loads, with a warning |
| nowhere | the pack loads, with a warning unless the module declares the package optional |
The rows are checked in that order. The JDK row comes before the host row because the host's loader
can usually load application-loader JDK classes, which would otherwise be reported as hidden Iris
classes. Whether a class belongs to such a module is decided by its package, from the JDK's module
descriptors (`ModuleFinder.ofSystem()`) and the loader the boot layer gives each module, so nothing
is loaded. When a jar uses several kinds of unusable class, the error has one group per kind and
jar, each with its own advice.
The JVM resolves a class only when code first needs it, so a class that nobody has is usually an
optional dependency of a bundled library, used only when present. Rejecting those would be stricter
@@ -138,6 +154,28 @@ logs one WARNING for the pack, one line per jar with at most five class names
class throws `NoClassDefFoundError` when it runs; the verifier may also need it while linking a
class that uses it, which then fails when that class is first used.
A module that knows its jar uses such classes declares their packages as optional in `info()`:
```java
public ModuleInfo info() {
return ModuleInfo.of("example:moss", "Moss", "1.0.0")
.withOptionalPackages("org.slf4j", "org.apache.logging.log4j");
}
```
Each package covers its subpackages. Missing classes of that jar inside them are dropped from the
warning and from `missingClasses()`; the rest still warn, and other jars of the pack are not
affected. `ModuleInfo.of(id, name, version)` declares none. Invalid names fail in `info()`, which the
load reports as a broken entry point of the jar.
The declaration lives in the entry point because all module metadata does. That fixes its timing:
`info()` exists only once the entry class is defined, after the reference check. This is safe
because the declaration only removes warnings. Every load error is decided in step 6, without it,
so a declared package can never turn a hidden Iris class, an unavailable JDK class or a class
missing from an exposed package into a pass. `missingClasses()` drops the excused classes instead
of flagging them: it then says exactly what the warning says, and a class the author declared
expected is not a problem to show in studio.
A class the host hides fails, even though the pack might never run that code, because it exists:
the module was written against Iris's copy, and the error says to ship the library or use the API
instead of leaving the author with a `NoClassDefFoundError` during install or generation.
+38 -13
View File
@@ -55,9 +55,10 @@ modules/moss.jar
com/example/moss/MossSettings.class
```
`info()` gives the module id, display name and version. The id's namespace is the namespace of
every stage the module defines; the name is what logs show. Names and versions must fit on one
line: line breaks and other control characters are rejected.
`info()` gives the module id, display name and version, and optionally the packages whose classes
the module expects may be missing (see below). The id's namespace is the namespace of every stage
the module defines; the name is what logs show. Names and versions must fit on one line: line
breaks and other control characters are rejected.
A module compiles against the Iris API as `compileOnly` (Maven: `provided`) and never ships it;
Iris provides the API at runtime. At runtime a module can use the Iris API (`com.volmit.*`), the
@@ -73,6 +74,23 @@ to Iris: module classes, and the libraries they shade, must not use them.
Libraries often reference optional integrations they only use when present. A class that neither
the pack, Iris nor the JDK has therefore does not fail the load: the pack loads, logs one warning
listing such classes per jar, and code that needs one throws `NoClassDefFoundError` when it runs.
A module that expects such classes to be absent declares their packages in `info()`, and the
warning leaves them out:
```java
public ModuleInfo info() {
return ModuleInfo.of("example:moss", "Moss", "1.0.0")
.withOptionalPackages("org.slf4j", "org.apache.logging.log4j"); // with subpackages
}
```
A declaration covers only that module's own jar. It never excuses a load error: a class Iris hides,
a JDK class modules cannot see or a class missing from an exposed package fails even inside a
declared package. Package names follow the rules of exposed packages (whole packages, trailing dot
accepted, wildcards rejected).
Modules see the JDK through the platform class loader. JDK modules outside it, such as
`jdk.compiler` and `jdk.jshell`, are not available to modules.
Iris never downloads modules and does not check which API version a jar was built for. A pack
ships its module jars, and keeping them compatible with the Iris version it targets is the pack
@@ -100,10 +118,12 @@ those packages, such as the ones that hold built-in modules' stage constants. It
point per jar, in jar file name order, and loads every jar of the pack through one class loader.
Closing it closes that loader. A pack without a `modules` directory has no modules. Errors name the
jar: no entry point, several entry points, a class of an exposed package in the jar, a class that is
also in another jar of the pack (both jars are named), a class that uses a class Iris has but hides
or a class missing from an exposed package, or an entry class that cannot be loaded, is not an
`IrisModule`, is not in that jar, or fails to construct. All checks before the last run before any
class of the pack is defined:
also in another jar of the pack (both jars are named), a class that uses a class Iris has but hides,
a class of a JDK module modules cannot see or a class missing from an exposed package, or an entry
class that cannot be loaded, is not an `IrisModule`, is not in that jar, fails to construct or whose
`info()` fails (an invalid optional package, for example). All checks before the last run before any
class of the pack is defined. The last error below lists every kind of unusable class the jar
uses, one group per kind:
```
Module jar modules/alpha.jar contains Iris API class com.volmit.FeatureAttachment and 130 more; Iris provides the API at runtime, so mark the Iris API dependency compileOnly (Maven: provided) and keep module classes out of com.volmit.*
@@ -114,13 +134,16 @@ Module jar modules/moss.jar uses classes that exist in Iris but are hidden from
com.example.moss.MossModule -> com.google.gson.Gson
com.example.moss.MossSettings -> art.arcane.iris.engine.object.IrisBiome
Modules cannot use Iris's own classes or its copies of libraries; ship the library in a module jar of the pack, or use the Iris API.
Module jar modules/moss.jar uses classes of JDK modules that are not available to modules:
com.example.moss.Scripts -> com.sun.source.tree.Tree (JDK module jdk.compiler)
Modules can use only the JDK modules of the platform class loader, such as java.base, java.sql and java.net.http.
Module jar modules/moss.jar uses classes that this Iris does not have, in packages Iris provides to modules:
com.example.moss.MossModule -> com.volmit.stage.NewerStage
The jar was built against a different Iris API or Iris version.
```
Classes that nobody has only produce a warning, also available as `pack.missingClasses()`:
Classes that nobody has only produce a warning, also available as `pack.missingClasses()`. Classes
in the optional packages a jar's module declares appear in neither:
```
Pack overworld: module jars use classes that neither the pack, Iris nor the JDK has, usually optional dependencies of a bundled library. The jars load, but code that needs these classes throws NoClassDefFoundError when it runs:
@@ -174,13 +197,15 @@ invocations and must not keep views or mutable state.
The tests cover graph resolution and every error path, fusion, activation cascade, outputs,
rejection and rollback, and install-order determinism. `PackModulesTest` compiles real module
jars into a temporary pack and loads them, including every jar error, duplicate classes in plain
and multi-release jars, API and other exposed classes in a jar, hidden host classes, classes missing
from an exposed package, optional dependencies that only warn, references that must still load
and multi-release jars, API and other exposed classes in a jar, hidden host classes, JDK classes
outside the platform loader, several kinds of unusable class in one error, classes missing from an
exposed package, optional dependencies that only warn, declared optional packages (fully and partly
excused, per jar, never excusing an error, invalid names), references that must still load
(arrays, the JDK, other pack jars, missing annotation types), linkage errors during install, and a
pack jar that requires a stage of a built-in module in `example.builtin`, outside `com.volmit`,
which loads only when the host exposes that package. `ExposedHostClassLoaderTest` checks what the
pack loader's parent shows and `ExposedPackagesTest` which package names it accepts and how they
match. `PackModulesSummaryTest` and `MissingClassesWarningTest` check the log texts. The example
pack loader's parent shows, `ExposedPackagesTest` which package names it accepts and how they
match, and `UnavailableJdkModulesTest` which JDK modules packs cannot see. `PackModulesSummaryTest` and `MissingClassesWarningTest` check the log texts. The example
ports in `src/test/java/com/volmit/example` rebuild preparation, anchoring, block writes, stilt and
snow as separate modules, add a third-party moss module, and add a two-module chunk pipeline. There
is no Minecraft integration or production storage in these tests.