Version 4.0 of office-stamper breaks the API on purpose. The engine was decoupled from docx4j, the document access moved behind a new SPI, and classes moved or changed shape across the board. A breaking release is legitimate — sometimes it is the only option — but breaking a library that people have built on is a promise you have to keep: nobody should discover the breakage at runtime, by surprise.
What follows is the practice I landed on for 4.0 — my working best guess, not a standard. If real users show me where it bends, this post gets corrected. Three tools carry the promise: shims for everything that can keep working unchanged, a migration guide for everything that cannot, and a machine-generated diff that makes the whole change auditable.
Shims first: the classes that never had to break
A class move does not have to be a break. Wherever old functionality survived with the same behavior, the provider module keeps a class at the pre-4.0 fully-qualified name, extending its new implementation:
// old location, new role
public class RemoveProofErrors extends pro.verron.officestamper.docx.preprocessors.RemoveProofErrors {
...
}
There are 26 of these shims in officestamper-docx4j11, covering the old utils subpackages, the
experimental entry points, and the pre-4.0 processor and resolver presets. The rule they follow
is one line in the module descriptor’s documentation: every shim extends the corresponding class
in the new location. That rule is testable, and the test is the interesting part — not “does the
old class exist”, but “is the old class still the same thing”:
assertInstanceOf(RemoveProofErrors.class,
new pro.verron.officestamper.preset.preprocessors.prooferror.RemoveProofErrors());
assertInstanceOf passes across the inheritance boundary, so code that type-checked against the
old name keeps type-checking, and instances created through the shim are real instances of the new
implementation. A shim that merely duplicated the class would pass a presence check and fail this
one.
One thing shims cannot fix: the old factory classes that lived directly in
pro.verron.officestamper.preset (OfficeStampers, Preprocessors, Postprocessors). The
engine’s docx4j-free preset package owns that name now, and a shim cannot squat on a package the
module system has already assigned. Those moved to docx.preset and the migration guide says so
explicitly — which is the general pattern: shim what you can, document loudly what you cannot.
The trap: same coordinates, different guts
The sneakiest migration hazard is not a removed class. It is a dependency that keeps its Maven coordinates while its contents change underneath them.
pro.verron.office-stamper:utils kept its coordinates in 4.0, but the 4.0 utils is docx4j-free:
every docx-coupled class it used to carry moved into the provider artifact. The failure mode when
you mix versions is ugly:
mixing the docx4j-coupled 3.9
utilswith the 4.0 engine produces duplicate/missing-class errors that name no obvious cause
That quote is from the migration guide itself, because it is the kind of failure a user cannot
debug from the stack trace. Half the classes resolve — whichever artifact the classpath picks
first — and the other half vanish or duplicate depending on declaration order. The guide’s fix is
one sentence: depend on the provider artifact and let it pull the matching utils; never keep a
standalone 3.x utils next to 4.0 modules.
The general rule for maintainers: when a module’s contents change semantic across a release, that is a compatibility break even when every coordinate is stable. Say so in the guide, in the exact words the user will need to search for.
The diff you can read
For the API surface that genuinely changed — the reshaped SPI, the narrowed processor contexts — there is japicmp. A Maven profile pins the previous release as the baseline and generates a modified-classes report:
<profile>
<id>apidiff</id>
<build>
<plugins>
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<configuration>
<oldVersions>
<dependency>
<groupId>pro.verron.office-stamper</groupId>
<artifactId>engine</artifactId>
<version>3.9</version>
</dependency>
</oldVersions>
<parameter>
<onlyModified>true</onlyModified>
<!-- the 3.9 engine references docx4j types that 4.0 no longer ships -->
<ignoreMissingClasses>true</ignoreMissingClasses>
<includes>
<include>pro.verron.officestamper.api</include>
<include>pro.verron.officestamper.preset</include>
<include>pro.verron.officestamper.utils</include>
</includes>
</parameter>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Two settings deserve explanation, because both are deliberate deviations from japicmp’s default use.
ignoreMissingClasses=true: the 3.9 engine’s signatures reference docx4j types that 4.0 does not
ship. Without the flag, japicmp drowns the real changes in missing-class noise that says nothing
about the API a user sees.
breakBuildOnBinaryIncompatibleModifications and breakBuildOnSourceIncompatibleModifications
are both false — for a release whose purpose is source incompatibility, letting the diff break
the build would be absurd. The diff is advisory: it must be visible, not fatal. The GitHub
workflow runs the profile on every pull request touching engine/**, utils/**, or the root
pom.xml, and uploads the report as an artifact named engine-api-diff-3.9-to-4.0, so a reviewer
can read exactly what a PR did to the compatibility story before merging it.
The caveat: advisory-only means someone has to look. The workflow makes looking cheap; it cannot make it happen.
The guide is a release artifact
The last tool is the least tool-like: compatibility.adoc, shipped on the project site, grown by
two hundred lines for this release. It has the expected sections — a numbered migration list, a
per-type mapping table classifying every moved type as reshaped-same-FQCN, same-FQCN-new-role,
deleted, or new. But the section that earns its keep is the porting example: a real processor,
before and after, chosen because it shows all three recurring moves at once.
// Before — 3.9
@Override
public void replaceWith(@Nullable String expression) {
if (expression == null) throw new OfficeStamperException("Cannot replace with null expression");
var from = comment().getStartTagRun();
var to = comment().getCommentRangeEnd();
paragraph().replace(from, to, new Insert(newRun(expression))); // docx4j WmlFactory.newRun
}
// After — 4.0
@Override
public void replaceWith(@Nullable String expression) {
if (expression == null) throw new OfficeStamperException("Cannot replace with null expression");
var from = comment().startAnchor();
var to = comment().endAnchor();
var run = context().part().factory().run(expression); // docx4j-free ElementFactory
paragraph().replace(from, to, new Insert(run));
}
Three moves: the context type narrows (ProcessorContext → CommentProcessorContext), the comment
accessors rename (getStartTagRun() → startAnchor()), and element creation goes through the
part’s ElementFactory instead of docx4j-typed WmlFactory helpers. A user porting a custom
processor reads this, matches the compile errors against the three moves, and is done in minutes
instead of hours. The guide ends with the instruction that makes the loop concrete: iterate until
the module compiles, then re-run your stamping tests.
My rule of thumb, for now
Stripped of office-stamper specifics, the recipe is short:
- Shim what can keep working. Old FQCN, extends the new class, pinned by an
assertInstanceOftest — presence is not enough. - Watch coordinates that outlive their contents. A dependency whose guts changed is a break; document the failure mode in the words a user would search for.
- Diff old against new on every change. japicmp against the last release, advisory but attached to review, so the compatibility cost of a PR is visible where the decision happens.
- Write the porting example first. If a real migration case cannot be shown before/after in twenty lines, the API change is probably not finished yet.
The diff report and the guide do not make the release less breaking. They make it accounted for — which is the only kind of breaking release a library with users gets to ship. And if your migration hits a case these tools miss, tell me: the guide and this post will both be revised.