DEV Community

Mohammad Mostafa Dastjerdi
Mohammad Mostafa Dastjerdi

Posted on Originally published at mohammadmd1383.github.io

Your library mod updated. What broke? Diff two mod jars and find every addon call site that hits it

A library mod you depend on goes from 1.4.2 to 2.0.0. The changelog says "cleaned up the registry API". Your addon still compiles in your head. Then a player sends you a NoSuchMethodError from the launcher log.

The question you need answered before you bump the version is: what changed in the public API, and which of my methods touch it? You can answer both from the jar files, with no IDE project and no decompiling by hand, using jdx, an open-source CLI (and MCP server) that reads Java/Kotlin bytecode.

Everything below was run with jdx 1.8.6 (the latest release) on small fixture jars: relicapi-1.4.2.jar, relicapi-2.0.0.jar (a made-up library mod with a fabric.mod.json), and mods/relicbags-1.1.0.jar, an addon compiled against 1.4.2. The output is pasted exactly as printed.

curl -fsSL https://raw.githubusercontent.com/MohammadMD1383/jdx/main/install-release.sh | bash
# Windows: irm https://raw.githubusercontent.com/MohammadMD1383/jdx/main/install-release.ps1 | iex
# needs JDK 21+
Enter fullscreen mode Exit fullscreen mode

Step 1: diff the two mod jars

$ jdx diff relicapi-1.4.2.jar relicapi-2.0.0.jar
api diff relicapi-1.4.2.jar -> relicapi-2.0.0.jar (public surface)
breaking  TYPE_MADE_FINAL  com.example.relicapi.api.RelicSlot
breaking  MEMBER_REMOVED  com.example.relicapi.api.RelicRegistry#register(java.lang.String, com.example.relicapi.api.Relic)
breaking  MEMBER_REMOVED  com.example.relicapi.api.RelicSlot#index
breaking  ABSTRACT_ADDED  com.example.relicapi.api.Relic#isCursed()
breaking  RETURN_TYPE_CHANGED  com.example.relicapi.api.Relic#getCooldownTicks(): int -> long
breaking  RETURN_TYPE_CHANGED  com.example.relicapi.api.RelicRegistry#get(java.lang.String): com.example.relicapi.api.Relic -> java.util.Optional
info  MEMBER_ADDED  com.example.relicapi.api.Relic#tier()
info  MEMBER_ADDED  com.example.relicapi.api.RelicRegistry#register(java.lang.String, java.lang.String, com.example.relicapi.api.Relic)
info  MEMBER_ADDED  com.example.relicapi.api.RelicSlot#index()
info  FIELD_CONSTANT_VALUE_CHANGED  com.example.relicapi.api.RelicSlot#MAX_SLOTS: 4 -> 6
6 breaking 路 0 suspicious 路 4 informational 路 0 types added 路 0 types removed
source: relicapi-1.4.2.jar (bytecode)
source: relicapi-2.0.0.jar (bytecode)
next: jdx members com.example.relicapi.api.RelicSlot
Enter fullscreen mode Exit fullscreen mode

Some notes for modders:

  • The most breaking findings come first. Each line names one rule (MEMBER_REMOVED, RETURN_TYPE_CHANGED, ABSTRACT_ADDED, ...), so you can filter by rule instead of matching on text.
  • A changed return type breaks binary compatibility. The JVM links a call by its full descriptor, so getCooldownTicks()I and getCooldownTicks()J are different methods. An addon built against 1.4.2 gets a NoSuchMethodError at runtime even though the source looks almost the same.
  • ABSTRACT_ADDED on an interface means every addon class that implements Relic without the new method throws AbstractMethodError when the game calls it.
  • FIELD_CONSTANT_VALUE_CHANGED is only informational, but it is easy to miss. static final constants are inlined at compile time, so an addon built against 1.4.2 keeps using 4 until you recompile it.
  • The ref on each line is already in jdx's canonical form, so you can paste it into the next command.

The default surface is public (public and protected, which is what an addon compiles against). Add --visibility all if you mixin into private members too.

Step 2: which of my methods hit those changes?

A diff gives you a list of changes. What you need is the list of your own methods that touch them. Put your addon jar and the old library jar on the classpath. Old, because your bytecode still refers to the old members. Then ask about each breaking ref:

$ jdx callers 'com.example.relicapi.api.RelicRegistry#register(java.lang.String, com.example.relicapi.api.Relic)' --jars 'mods/*.jar' --jars relicapi-1.4.2.jar
callers of 'com.example.relicapi.api.RelicRegistry#register(java.lang.String, com.example.relicapi.api.Relic)'
  call com.example.relicbags.RelicBags#onInitialize()  relicbags-1.1.0.jar
Enter fullscreen mode Exit fullscreen mode
$ jdx callers 'com.example.relicapi.api.Relic#getCooldownTicks()' --jars 'mods/*.jar' --jars relicapi-1.4.2.jar
callers of 'com.example.relicapi.api.Relic#getCooldownTicks()'
  call com.example.relicbags.RelicBags#onInitialize()  relicbags-1.1.0.jar
Enter fullscreen mode Exit fullscreen mode

A field is not a method, so for the index field that became private you use usages (here --in limits the output to the addon jar):

$ jdx usages 'com.example.relicapi.api.RelicSlot#index' --in 'relicbags*' --jars 'mods/*.jar' --jars relicapi-1.4.2.jar
usages of 'com.example.relicapi.api.RelicSlot#index'
relicbags-1.1.0.jar (1)
  read com.example.relicbags.BagScreen#firstSlotIndex(com.example.relicapi.api.RelicSlot)  BagScreen.java:4
Enter fullscreen mode Exit fullscreen mode

That is a file and a line number, read from the LineNumberTable in the addon's bytecode.

For ABSTRACT_ADDED, the question is "who implements this interface?":

$ jdx implementors com.example.relicapi.api.Relic --jars 'mods/*.jar' --jars relicapi-1.4.2.jar
hierarchy of 'com.example.relicapi.api.Relic'
  subtypes in workspace (1)
    class com.example.relicbags.SatchelRelic  relicbags-1.1.0.jar
Enter fullscreen mode Exit fullscreen mode

SatchelRelic must now implement isCursed(). Its int getCooldownTicks() also no longer overrides anything, because 2.0.0 declares long getCooldownTicks().

Last, check the replacement API in the new jar before you rewrite the call:

$ jdx signature 'com.example.relicapi.api.RelicRegistry#register' --jars relicapi-2.0.0.jar
signatures of com.example.relicapi.api.RelicRegistry#register
  public static void register(java.lang.String namespace, java.lang.String path, com.example.relicapi.api.Relic relic)
source: relicapi-2.0.0.jar (bytecode)
next: jdx show com.example.relicapi.api.RelicRegistry
Enter fullscreen mode Exit fullscreen mode

This took four lookups and no launcher run. Each of the three source files that need edits is named: RelicBags, BagScreen and SatchelRelic.

Step 3: loop over every breaking ref

--json gives you the same report as data, so you can feed the breaking refs into the lookups above:

$ jdx diff relicapi-1.4.2.jar relicapi-2.0.0.jar --json | jq -r '.result.findings[] | select(.severity=="breaking") | .ref'
com.example.relicapi.api.RelicSlot
com.example.relicapi.api.RelicRegistry#register(java.lang.String, com.example.relicapi.api.Relic)
com.example.relicapi.api.RelicSlot#index
com.example.relicapi.api.Relic#isCursed()
com.example.relicapi.api.Relic#getCooldownTicks()
com.example.relicapi.api.RelicRegistry#get(java.lang.String)
Enter fullscreen mode Exit fullscreen mode

Each finding also has severity, rule, type and detail (for example "int -> long").

Step 4: gate your own library's releases

If you are the one publishing the library mod, run the check the other way: compare your last release against the new build in CI. diff exits 0 whenever the comparison ran. Add --fail-on breaking to turn breaking changes into exit 1:

$ jdx diff relicapi-1.4.2.jar relicapi-2.0.0.jar --severity breaking --fail-on breaking
api diff relicapi-1.4.2.jar -> relicapi-2.0.0.jar (public surface)
breaking  TYPE_MADE_FINAL  com.example.relicapi.api.RelicSlot
breaking  MEMBER_REMOVED  com.example.relicapi.api.RelicRegistry#register(java.lang.String, com.example.relicapi.api.Relic)
breaking  MEMBER_REMOVED  com.example.relicapi.api.RelicSlot#index
breaking  ABSTRACT_ADDED  com.example.relicapi.api.Relic#isCursed()
breaking  RETURN_TYPE_CHANGED  com.example.relicapi.api.Relic#getCooldownTicks(): int -> long
breaking  RETURN_TYPE_CHANGED  com.example.relicapi.api.RelicRegistry#get(java.lang.String): com.example.relicapi.api.Relic -> java.util.Optional
4 findings below --severity breaking
6 breaking 路 0 suspicious 路 4 informational 路 0 types added 路 0 types removed
fail-on breaking: 6 breaking changes (exit 1)
source: relicapi-1.4.2.jar (bytecode)
source: relicapi-2.0.0.jar (bytecode)
next: jdx members com.example.relicapi.api.RelicSlot
Enter fullscreen mode Exit fullscreen mode

The tally always covers the whole comparison, even when --severity hides some lines. A build with no API change prints no differences (3 types compared) and exits 0. If you meant to break things (it is 2.0.0, after all), the report is a ready-made "Breaking changes" section for your changelog.

Honest caveats

  • jdx does not remap. It reads names exactly as they are stored in the jar. A mod jar from Modrinth or CurseForge built for Fabric or Quilt uses intermediary names for game classes, while your dev build uses Yarn or Mojang names. If your question involves Minecraft classes, pass the Loom-mapped jar that Fabric Loom or NeoForge ModDevGradle already wrote, with --jars (for callers/usages/signature) or as a diff argument.
  • diff only works within one mapping namespace. Yarn vs Mojmap, or intermediary vs named, share almost no names, so the report looks like everything was removed and re-added. That comparison is meaningless. Compare two jars that use the same names: two builds of a library compiled in one namespace (as here, where the library's own package names are not remapped), or two Loom-mapped Minecraft jars with the same mappings. Remapping is tracked in #24.
  • It compares bytecode, not behavior. If a method keeps its signature but its meaning changes, the diff cannot see it. Use jdx body on both jars for that.
  • Reflection and string-based lookups are invisible to callers/usages, and so are mixin targets that are written as strings. Check your mixin configs separately.
  • callers and usages here are a static index of your jars, not a running game.

Links

Top comments (0)