unmodifiableList instead of List.copyOf in Try
Context
Try.Partition and the Try collectors return immutable lists of successful values. Try.run() produces Success(null), and those nulls can appear in the result lists of sequence/partitioningBy.
Decision
Try uses Collections.unmodifiableList(new ArrayList<>(...)) instead of List.copyOf for lists of successful values.
Consequences
Positive:
- Preserves
nullelements in the list (produced byTry.run()). sequence(List.of(Try.run(() -> {})))returnsSuccess([null])without throwing NPE.
Negative / tradeoffs:
unmodifiableListallowsnullinternally;List.copyOfis stricter and clearer about nullability.- Behavioural difference with
Result, which does useList.copyOf(becauseOkguarantees non-null).
Alternatives considered
List.copyOfin both: breaks compatibility withTry.run()andTry<Void>.- Prohibit null in
Success: removes the ability to represent void side-effects without aUnittype.