14 KiB
Java migration — working handoff
Start here when picking the migration up in a fresh session. This file holds the operational knowledge: how to work, what breaks, and what is left. The other documents hold the reasoning.
| Document | What it is |
|---|---|
JAVA_MIGRATION.md |
The plan, phase state, and a running findings log |
JAVA_MIGRATION_ABI_INVENTORY.md |
Which downstream mods use what. The authority on whether anything is load-bearing |
JAVA_MIGRATION_CONSUMER_AUDIT.md |
How every consumer uses FMP at runtime: data, lifecycle, reflection, and generated tiles |
JAVA_MIGRATION_DIVERGENCES.md |
Every intentional difference from the reference, one entry per port |
JAVA_MIGRATION_MANUAL_CHECKS.md |
What no automated test can cover, and must be checked by hand in a client |
Branch: algent/java. Base: master. 54 commits so far.
The one rule that matters
Check both consumer audits before changing a compatibility surface. The ABI inventory is the authority on what must link; the source-level audit is the authority on behavior, serialized data, reflection, and mixin field access.
Workflow per type
Followed for every port so far. It has caught three real ABI breaks that inspection missed.
- Characterize first, commit separately. Write tests against the untouched Scala and confirm they pass. Commit as
test: characterize Xbefore touching the implementation. - Freeze a binary consumer if the inventory shows a load-bearing
$classor singleton. Recipe below. - Port. Delete the
.scala, add the.java. - Verify. Same tests must pass unchanged, plus the ABI diff below.
- Document in
JAVA_MIGRATION_DIVERGENCES.md, then commit asrefactor: port X to Java.
If a characterization test will not compile after the port, that is a signal, not an inconvenience. Twice it was a real
ABI change (MissingMicroMaterial forwarders, the ACC_SYNTHETIC super accessor). Investigate before adjusting the
test, and if you do adjust it, re-run it against the stashed Scala to prove the baseline still holds.
Commands
./gradlew spotlessApply checkstyleTest build
./gradlew test
./gradlew runFunctionalTestServer
Test result counts (the Gradle output does not print them):
awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" errors="e}' build/test-results/test/TEST-*.xml
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
Current baseline: 130 plain-JVM tests, 25 Forge server tests, all passing at their last completed runs.
ABI diff against the reference
Build a reference jar at the pre-port commit, then diff. This is the check that matters most.
git stash push -u -- src/main && ./gradlew build -x test -q && cp "$(ls -t build/libs/*dev.jar | head -1)" /tmp/ref.jar && git stash pop && ./gradlew build -x test -q
Then, for each converted type, compare public members by name and by descriptor separately. Descriptor counts
alone are ambiguous, and javap renders varargs and generics in ways that look like losses but are not:
diff <(javap -p -cp /tmp/ref.jar codechicken.multipart.X | grep " public" | sort) <(javap -p -cp "$NEW" codechicken.multipart.X | grep " public" | sort)
diff <(javap -p -s -cp /tmp/ref.jar codechicken.multipart.X | grep descriptor | sort) <(javap -p -s -cp "$NEW" codechicken.multipart.X | grep descriptor | sort)
Also diff the emitted class list, to catch removed $$anonfun$ artifacts that belong in the divergence log:
diff <(unzip -Z1 /tmp/ref.jar | grep X | sort) <(unzip -Z1 "$NEW" | grep X | sort)
Re-running the downstream inventory
java tools/AbiScan.java "<instance>/.minecraft/mods" ForgeMultipart
Needs JDK 17+. The frozen baseline is src/test/fixtures/abi/gtnh-daily-678-consumers.txt, from GTNH daily
2026-08-14+678 (241 jars, 27 consumers). Diff against it; anything present there but absent from the port is a
linkage break in a shipping mod.
Building a frozen Scala consumer fixture
Scala 2.11.5 must run under Java 8 — it cannot find java.lang.Object on a modern JDK.
- Build a reference dev jar at the pre-port commit.
- Get the compile classpath once, via an init script registering a task that prints
sourceSets.main.compileClasspath.asPath. - Compile with
scala.tools.nsc.Main,-target:jvm-1.8, classpath = reference jar + that classpath. base64 -w 76the class intosrc/test/resources/compat/, and record both SHA-256s insrc/test/fixtures/README.md.
Eight fixtures exist already; copy the pattern from any *BinaryCompatibilityTest. They decode and defineClass the
frozen bytes, so recompiling against the port would defeat the point.
Gotchas, all discovered the hard way
Default methods vs superclass. Emit a Java default only when no class in an implementor's superclass chain
declares the same member. A superclass method always beats an interface default on the JVM, and the failure is
silent. TFacePart, TEdgePart, Saw, JIconHitEffects.getBreakingIcon and IMicroMaterial's three members passed
this test. TCuboidPart, TNormalOcclusion, TIconHitEffects, TItemMultiPart.onItemUse and
TRandomUpdateTick.onWorldJoin failed it and had to stay abstract with explicit forwarders in implementors.
Audit existing super call sites, not just missing overrides. PostMicroblock already overrode occlusionTest
and ended with super.occlusionTest(npart), which used to route through the trait. After the port it reached the
superclass directly and silently dropped the box test, while still compiling.
A trait gaining a default changes its concrete implementors. ItemSaw and MissingMicroMaterial stopped
declaring members they never overrode, because Scala no longer emits a forwarder. Diff those classes too.
Scala trait extending a class is a bare interface in bytecode. It carries none of the class's members, so Java
code must cast. Seen with JIconHitEffects, TRandomUpdateTick, TileMultipartClient. There will be more.
Trait super accessors are ACC_SYNTHETIC. javac cannot see or implement them. Where one is load-bearing, emit
it as a non-synthetic default returning the identity for the chain, as
codechicken$multipart$TNormalOcclusion$$super$occlusionTest does.
Recompiled Scala consumers. These are source-only breaks; binaries are fine. Expect and document them:
x.partList(i) becomes x.partList.apply(i); assignment to a Java accessor needs _$eq; a Scala object becoming a
Java class loses apply sugar and must be referenced as X$.MODULE$ when passed as a value; Tuple2 members typed
Boolean in Scala arrive as Object and need casting; and Scala 2.11 will not adapt a lambda to
Function1[_, BoxedUnit], so operate { p => ... } needs an explicit AbstractFunction1.
A companion object can be load-bearing without a single bytecode reference. The inventory's 17 MODULE$ list is
not the whole test — check the reflective string constants too. MultipartHelper$ is in neither the MODULE$ list nor
any consumer's constant pool as a type, but guidenh names it as a string, so it was kept. IconHitEffects$ was in
neither and was dropped. Check both lists before deleting a companion.
Classes that cannot class-initialize headless make good probes. MultipartSaveLoad reflects into TileEntity's
static maps through ObfMapping and always throws under a plain JVM. That turns "did this branch reach the loader?"
into an assertion: returning normally proves the guard short-circuited, and assertThrows(LinkageError.class, ...)
proves the other branch did reach it. Use LinkageError, not the exact type — the first attempt raises
ExceptionInInitializerError and every later one raises NoClassDefFoundError, so test order would otherwise matter.
Where a trait member cannot be a default, use an interface static. TScheduledPacketPart.read is shadowed by
TMultiPart.read, so the dispatch that lived in the $class helper became
TScheduledPacketPart.readMask(part, packet), with a one-line forwarder documented in the javadoc. Same shape as a
$class bridge, but idiomatic and callable from Java.
private[multipart] becomes public, not package-private. It reaches codechicken.multipart.handler too, and Java
has no scope spanning a package and its siblings. PacketScheduler.sendScheduled hit this; MultipartGenerator and
MicroblockGenerator will too.
A Forge FakePlayer unlocks the server half of player-dependent code.
FakePlayerFactory.getMinecraft(worldServer) needs no connection and its world is not remote, which is the branch a
server takes. It made ControlKeyModifer.isControlDown testable. The client branch of anything stays manual.
A Scala package object cannot be ported. It compiles to a class named package, and that is a Java keyword, so
no Java source can declare or name it. Both were removed by inlining their single member. Any future one has the same
three options: leave it in Scala, invent a Java type to hold its members, or inline it.
Scala's uniform access hides field versus no-arg method. renderer.hasOverrideBlockTexture reads the same in
Scala either way; it is a method on RenderBlocks and Java needs the parentheses. It fails at compile time rather than
silently, but expect it in every remaining renderer conversion.
Java 8 target. No List.of, no var, no switch expressions in main or test sources.
Two test classes sharing global registry state must guard their registrations, and the registries' error paths call
a logger that is null until preInit, so they cannot run headless at all.
What is done
All eight load-bearing $class helpers from the inventory, both registries, and the two central types:
IDWriter, PartialOcclusionTest/JPartialOcclusion, TCuboidPart/JCuboidPart, the TNormalOcclusion unit,
TFacePart, the TIconHitEffects unit, TItemMultiPart/JItemMultiPart, TEdgePart, Saw, MicroMaterialRegistry,
MultiPartRegistry, TileMultipart, TMultiPart, TickScheduler, BlockMultipart.
Plus the six marker interfaces: TSlottedPart, IRandomDisplayTick, INeighborTileChange, TRandomUpdateTick,
ISidedHollowConnect, IMicroMaterialRender, plus MultipartHelper, TileCache, PacketScheduler and the ControlKeyModifer pair.
Both package.scala objects are gone, removed rather than ported. MultipartRenderer is done.
72 Java files, 48 Scala files, ~6,376 Scala lines left (non-blank; that is the metric this figure has always used).
What is left, and in what order
The low-risk queue is empty. Pick the next piece deliberately rather than off the top of a list.
The Schematica registry blocker is repaired. MultiPartRegistry$ again has the exact private field
codechicken$multipart$MultiPartRegistry$$typeMap with a Scala mutable-map descriptor. It is a live wrapper over the
canonical Java map, and MultiPartRegistryCharacterizationTest reproduces Schematica's reflective lookup and proves
both views reach the same factory.
The source-only member guards are also complete: GuideNH's mixin fields, Et Futurum's button arrays, Iguana's saw
field, and Galacticraft's name-only registration lookup are pinned by ConsumerReflectionCompatibilityTest.
Tile list/order/slot behavior and the live move lifecycle are now frozen by focused plain-JVM and Forge tests. They
pin ordered parts/id NBT, published list views, slot rebinding, add/remove/replace behavior, and the relocation
sequence (onWorldSeparate, then onMoved/onWorldJoin) while preserving the original generated tile.
The same ordered torch/button pair now supplies a compact NBT fixture and an exact logical chunk-description fixture. The latter pins FMP's framing and payload before CodeChickenLib applies deferred transport compression.
Next freeze representative generated Scala/Java traits and pass-through interfaces. The checklist is in the
"Immediate compatibility gate" section of JAVA_MIGRATION.md.
IRedstonePart.scala is misleadingly named and is not a marker-trait file. It holds six traits plus
RedstoneInteractions, whose MODULE$ is load-bearing. After the compatibility gate and an initial profile, port the
whole file as one medium-risk unit; do not split its mutually dependent behavior into smaller commits.
Medium. The handler packages on both sides, MultipartRenderer, MicroRecipe, ItemMicroPart,
MicroblockPlacement, PlacementGrids, BlockMicroMaterial, MissingMicroMaterial, ConfigContent,
DefaultContent.
Phase 5, needs the registerJavaTrait path. TileMultipartClient and everything in multipart/scalatraits/.
These are registered with the ASM generator; converting them is a different mechanism with documented restrictions.
Do the pilot deliberately, as its own piece of work.
Phase 6/7, last. Microblock and the microblock shape hierarchy, MicroblockGenerator, MultipartGenerator, and
all of multipart/asm/. The ASM subsystem should be last; freeze generated-class fixtures before touching it.
Known gaps
- The full manual checklist has not been completed. Limited smoke testing has been performed in the GTNH full pack, but individual checklist items remain unrecorded and unverified.
Every port since
TCuboidParthas deferred something to it, andBlockMultipartleans on it hardest: breaking, selection boxes, collision, pick block, activation, particles and light are covered by nothing automated. Run it in a real client before this branch goes near a release. - No CPU or allocation profiles exist. Phase 4 has not started, so there is no baseline to compare against.
- Microblock-specific NBT and packet payloads still need characterization immediately before that subsystem changes; the compact core tile/part fixture is complete.
TileMultipart'spartListstill republishes an immutable ScalaSeqon every mutation, andoperatestill allocates aFunction1per call. Both are faithful to the reference and both are deliberately left for Phase 4, which needs profiling first.- Phase 1 never properly started. GTNHLib is currently commented out in
dependencies.gradle; it had been added atapiscope to satisfy a test compile rather than because a migration change needed it.