Remove Map.computeIfAbsent and computeIfPresent #278
All Vouch review confidence checks passed
Residual risk 0.46 = Change Risk (0.52) × (1 − Review Confidence (0.12)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 10% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #278"
general
weight: 0.35
copilot-pull-request-reviewer[bot]
Ticket
Closes #273
Tracker: #247
What changed and why
Before,
Map,SortedMap,HashMap,LinkedHashMap,TreeMap,NonEmptyMapandNonEmptySortedMaphadcomputeIfAbsent(K, Function)andcomputeIfPresent(K, BiFunction), returning aTuple2of the value and the map.updateWith(#274) covers both, so, as the maintainer decided on 2026-10-04 in the issue, they are removed, notdeprecated: Zazr makes no compatibility promise before 1.0, and Scala 2.13's immutable maps have neither.
After:
Maps.computeIfAbsentandMaps.computeIfPresent, which nothing else called.The class javadoc of the two non-empty maps no longer lists them.
java.util.MapcomputeIfAbsent/computeIfPresentof theasJava()views (MapViews) stay:java.util.Mapdeclares them, and they throw
UnsupportedOperationExceptionas every mutator of the views.zazr-test,zazr-jackson,zazr-avaje-jsonb, the benchmarks, the docsexamples and the skill examples had none either (
git grep computeIf). The only callers were the tests of theremoved methods.
Release notes (0.4.0)
Map.computeIfAbsentandMap.computeIfPresentare removed from every Zazr map; useupdateWith:m.computeIfAbsent(k, f)→m.get(k)/m.updateWith(k, o -> o.orElse(() -> Option.some(f.apply(k))));for the value alone,
m.getOrElse(k, () -> f.apply(k))m.computeIfPresent(k, f)→m.updateWith(k, o -> o.map(v -> f.apply(k, v)))NonEmptyMapandNonEmptySortedMap,updateWithreturns the plain map; to keep the non-empty type:m.containsKey(k) ? m : m.put(k, f.apply(k))andm.get(k).fold(() -> m, v -> m.put(k, f.apply(k, v)))Each line was compiled against
zazr-core/target/classesin a generic method taking the old parameter types(
Function<? super K, ? extends V>,BiFunction<? super K, ? super V, ? extends V>) onMap,NonEmptyMapandNonEmptySortedMap, and run:Decisions beyond the ticket
1. The non-empty release-note line. The issue's replacements return
HashMap/TreeMapon the non-empty maps,where the removed methods returned the non-empty type, so a migrating caller gets a type error. I added a
replacement that keeps the type (above, and in the design row). Alternative: leave it out; rejected, since the
notes would then not compile for those callers.
2.
euler/Memoize.javais unchanged. ItscomputeIfAbsentisjava.util.concurrent.ConcurrentHashMap's, notZazr's, so the removal does not touch it, and on a hit it already does one lookup. The second memoizer in the file
uses a JDK
HashMapwithget/put. Rewriting it with a Zazr map would change a test helper for no reason.3. The
ABSENTsentinel tests are rewritten, not dropped.HashMapTest,LinkedHashMapTestandTreeMapTesthad
computeIfAbsentOnAbsentKeyComputesandcomputeIfPresentOnAbsentKeyIsNoopinAbsentSentinelTests, theguard that the sentinel never leaks. They become
updateWithOnAbsentKeyHandsNoneToF,updateWithRemovingAnAbsentKeyGivesTheMapItselfandgetOrElseWithASupplierOnAbsentKeyCallsIt, the same guardover the methods that now read the sentinel.
4.
docs/design.md3.6, 3.7 and 3.9 listed the methods (the non-empty "returns the non-empty type" list, whatMapkeeps, and the null rules). The first two now say they were removed on 2026-10-04; in 3.9 the null-argumentexample is now
updateWith, which also rejects a nullfon a missing key.5. Two test methods were renamed now that they test no
compute:NonEmptyMapTest.shouldMergeAndCompute→shouldMerge,NonEmptySortedMapTest.shouldPutMergeAndComputeKeepingTheComparator→shouldPutAndMergeKeepingTheComparator.Tests
ComputeifabsentTests/ComputeIfPresentTestsnested classes and the two null-result tests inGetWithNullsTestsofHashMapTest,LinkedHashMapTestandTreeMapTest; the twocomputenull-argument testsof
MapFunctionArgumentTest; thecomputeassertions andNonEmptyGuaranteerows ofNonEmptyMapTestandNonEmptySortedMapTest(the reflective guard there checks the rows match the public methods, so it confirms theremoval).
updateWithkeeps is tested byMapUpdateWithTest(#274): put on an absentkey, the map itself when nothing changes, a null result rejected by name (
shouldRejectANullResultNamingTheType),on all five maps; and by
MapFunctionArgumentTest.shouldRejectANullFunctionInUpdateWithfor a null function,key present or absent, map empty or not.
AbsentSentinelTestsabove, on the three maps.Mutation check
One at a time, on the committed tree, each reverted with
git checkout -- <file>:<details><summary>(a) <code>Maps.updateWith</code> hands <code>Some(ABSENT)</code> to <code>f</code> for an absent key</summary>
</details>
Failed:
HashMapTest$AbsentSentinelTests.updateWithOnAbsentKeyHandsNoneToF,LinkedHashMapTest$AbsentSentinelTests.updateWithOnAbsentKeyHandsNoneToF.<details><summary>(b) <code>Maps.getOrElse(map, key, supplier, …)</code> skips the <code>ABSENT</code> check</summary>
</details>
Failed:
HashMapTest$AbsentSentinelTests.getOrElseWithASupplierOnAbsentKeyCallsIt,LinkedHashMapTest$AbsentSentinelTests.getOrElseWithASupplierOnAbsentKeyCallsIt(ClassCastException).<details><summary>(c) <code>TreeMap.updateWith</code> hands <code>Some(ABSENT)</code> to <code>f</code></summary>
</details>
Failed:
TreeMapTest$AbsentSentinelTests.updateWithOnAbsentKeyHandsNoneToF.Checks run
make verifyon 8f9c28b1a: green (zazr-core 13896 tests, 0 failures). 1b1015542 only changesdocs/design.md.make siteon 8f9c28b1a: built, no warnings.make docs-complexityregenerateddocs/collections/complexity.md(the sixcomputerows go).Docs
docs/design.md: row 3.3 ofupdateWithcloses the open question; a new 3.3 row records the removal (decided bythe maintainer 2026-10-04, #273) with the replacements, the reasons and the two-lookup trade-off; 3.6, 3.7 and 3.9
updated (above).
docs/vavr.md(the migration guide): a "Removed" row,computeIfAbsent,computeIfPresent→updateWith, thelazy
getOrElse.skills/zazr/references/from-vavr.md: the same row with the replacement lambdas. The other skill references anddocs/collections/maps.mdnever mentioned the methods; they already teachupdateWithand the lazygetOrElse.docs/collections/complexity.md: regenerated.git grep -n computeIfstill finds, and why each stays:-
docs/design.md: the decision log recording the removal.-
docs/vavr.md,skills/zazr/references/from-vavr.md: the migration rows naming the Vavr method.-
internal/MapViews.java,JavaViewMutatorTest: thejava.util.Mapmethods of theasJava()views, kept.-
internal/Collections.java:java.util.LinkedHashMap.computeIfAbsenton a JDK map, ingroupBy/groupMap.-
euler/Memoize.java:ConcurrentHashMap.computeIfAbsentand a comment about it (decision 2).Found but not fixed
None.