You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 21153e3
Browse filesBrowse the repository at this point in the historyBrowse files
Move the shared javax.crypto.KEM SPI prologue off jcajce.util.SpiUtil, whose jdk25 twin cannot carry it, onto the never-overlaid KemSpiUtil, so that encapsulate and decapsulate no longer fail with NoSuchMethodError on a JDK 25 runtime, where the jdk17-only SPIs resolve against the versions/25 copy of the hook, with a src/test/jdk25 regression test because test25 is the only task that puts a JDK 25 in front of the multi-release jar and the eleven jdk17 KEM tests cannot see the mismatch, and the rule recorded in the architecture guide.
Copy file name to clipboardExpand all lines: docs/claude/architecture.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,56 @@ Before changing a method in `src/main/java`, check whether that class has a vers
36
36
37
37
Because MR-jar resolution is per class file, a **base-tree class can call a class that is overlaid** — on JDK ≥ N the versioned copy is loaded even though the caller came from the jar root. `ECUtil.getNameFrom` → `SpecUtil` (jdk1.11 twin adds the `NamedParameterSpec` fast path) was the original example. So when a provider SPI needs version-specific behaviour, don't fork the whole SPI into `src/main/jdk1.N` — keep the SPI (and its registered inner classes) once in the base tree, and route the genuinely version-specific pieces through a small package-private hook class whose jdk1.N twin swaps them. The `edec` package is the worked example after its 2026 de-duplication: the five SPIs exist only in base and delegate key construction/conversion to `XDHKeys` (jdk1.11 twin: `XECKey` integration) and `EdDSAKeys` (jdk1.15 twin: `EdECKey` + JDK `EdDSAParameterSpec` bridging), with shared byte-level helpers in the never-overlaid `EdECUtil`. The pre-restructure whole-SPI forks had accumulated four behavioural drifts (UKM salt ignored, `EMULATE_ORACLE` dead, RFC 8418 registrations missing per github #2131, third-party-key fallback lost) — the hook shape makes that class of drift impossible, and shrinks what must be kept in step to the hook's method set (state the twin-sync rule in both copies' javadoc). Base copies of hook methods that only exist for a newer JDK return null ("not bridged here"), and the base tree must stay Java-4-source-floor clean since new base classes are swept into the legacy Ant builds.
38
38
39
+
### The mirror-image trap: an overlaid class must not host code a lower overlay calls
40
+
41
+
The hook pattern above works because resolution is per class file — but that cuts both ways, and the
42
+
reverse direction is a runtime `NoSuchMethodError` rather than silent drift. If class `H` exists in
43
+
`jdk17`**and**`jdk25`, and class `C` exists **only** in `jdk17`, then on a JDK 25 runtime `C` loads
44
+
from `META-INF/versions/17` while `H` loads from `META-INF/versions/25`. A call from `C` to a method
45
+
that only the jdk17 copy of `H` defines compiles fine (javac sees one `H` per source set) and dies at
46
+
the call site on JDK 25 only.
47
+
48
+
So: **a class that has versioned twins is a version hook and nothing else.** Put the version-varying
49
+
answers on it and nothing more; shared helper bodies belong on a class with *no* twin anywhere above
50
+
the overlay that calls it. `org.bouncycastle.jcajce.util.SpiUtil` is the cautionary example — it
51
+
exists in base/`jdk17`/`jdk25` purely so `hasKDF()` / `hasKEM()` can differ, and when the twenty
52
+
`javax.crypto.KEM` SPI classes (`jdk17`-only) had their shared prologue extracted onto it, every
53
+
encapsulate and decapsulate threw `NoSuchMethodError` on JDK 25 while JDK 21 stayed green. The fix
54
+
was to move the two helpers to `jcajce.provider.asymmetric.util.KemSpiUtil`, a `jdk17`-only class in
55
+
a package with no overlay above the base tree, and to say so in both classes' javadoc.
56
+
57
+
Checking this is mechanical, and worth doing whenever you add a cross-class call inside an overlay:
58
+
for the callee, `find <module>/src/main -name <Callee>.java` — if that lists a directory whose
59
+
version is **higher** than the caller's, the call is unsafe. Confirm against the built jar rather
60
+
than the source tree, since the jar is what resolves:
61
+
62
+
```
63
+
unzip -l <module>/build/libs/bcprov-jdk18on-*.jar | grep '<Callee>.class' # one entry per overlay
64
+
```
65
+
66
+
Two entries at `versions/17` and `versions/25` for the callee, one at `versions/17` for the caller,
67
+
is the broken shape.
68
+
39
69
Crucially, the MR overlay's behaviour is **not covered by the normal test suite**. The `test11`/`test15`/`test17`/`test25` tasks run *only* the classes compiled from `src/test/jdk1.N` (their `testClassesDirs`), wired through the `AllTests11`/`AllTests15`/… suites — the base `src/test/java` tests are on the classpath but are **not executed** there. So a base test that would catch the drift never runs against the MR-jar, and the divergence ships undetected. When you touch (or find drift in) an MR-overlaid class, add a `src/test/jdk1.N` test that exercises the overlaid path against the multi-release jar and register it in the matching `AllTestsN` suite. A thin JUnit `TestCase` that runs the relevant base `SimpleTest` via `new XxxTest().perform()` / `assertTrue(result.isSuccessful())` reuses the existing vectors without duplication — see `prov/src/test/jdk1.11|jdk1.15/.../OpenSSHKeyFactoryMRTest.java`, added after the `edec` `KeyFactorySpi` OpenSSH path was found to have drifted (jdk1.11/jdk1.15 lacked passphrase support and threw the wrong exception type, uncaught because no `test11`/`test15` test covered it).
40
70
71
+
**Which overlay's test tree, though?** Each `testN` task is the *only* one that puts a JDK N runtime
72
+
in front of the multi-release jar, so a test only ever exercises the resolution its own version
73
+
produces. A test under `src/test/jdk17` cannot see a jdk17-vs-jdk25 mismatch at all: there the caller
74
+
and every hook alike come from `versions/17`. So when a class in overlay N calls anything that has a
75
+
copy in a *higher* overlay, the test has to go in the **highest** overlay's test tree — today
76
+
`src/test/jdk25`, run by `test25` (`BC_JDK25` must be exported for it to run at all; each task is
77
+
`onlyIf` its `BC_JDK<N>` env var is set, so an unset one skips silently and prints nothing).
78
+
79
+
This is exactly how the `SpiUtil` break above shipped: eleven `*KEM17Test` classes covered all ten
80
+
KEM families through `javax.crypto.KEM` under `src/test/jdk17`, and every one passed, while
81
+
`src/test/jdk25` held three KDF tests and nothing else — so the jdk17-only SPIs had no JDK 25
82
+
coverage of any kind. `prov/src/test/jdk25/.../KemSpiMRTest.java` closes it, and is the model: pick
83
+
one class per SPI *package tree* rather than all of them (they share the helper, so one is enough to
84
+
catch a break) and add an `AllTests25` in its package, since `test25`'s filter is
85
+
`includeTestsMatching "AllTest*"`. Note `test25` emits its results as the HTML report plus
86
+
`test-results/test25/binary`, not per-class XML — read
87
+
`prov/build/reports/tests/test25/index.html` for the counts rather than looking for `TEST-*.xml`.
88
+
41
89
## Update `module-info.java` when you add or remove package
42
90
43
91
Each Gradle-built module has a JPMS descriptor at `<module>/src/main/jdk1.9/module-info.java` (e.g. `prov/src/main/jdk1.9/module-info.java`, `pkix/src/main/jdk1.9/module-info.java`) listing every exported package. The Java 8 sources under `<module>/src/main/java` and the descriptor are bundled into the same multi-release jar; the descriptor is the source of truth for what's visible when downstream code runs on JDK 9+ with `--module-path`. A package that exists in the source tree but isn't listed in `module-info.java` is invisible to modular consumers — class-path consumers still see it, which is why the omission is easy to miss locally. Note: `core` itself has no module-info; its sources are bundled into the published `bcprov` jar via the core-into-prov srcDirs trick, so the `prov` module-info exports `core` packages.
0 commit comments