RFR: 8351565: Implement JEP 502: Stable Values (Preview) [v6]

Luca Kellermann duke at openjdk.org
Mon Mar 17 02:01:59 UTC 2025


On Sun, 16 Mar 2025 00:34:45 GMT, John R Rose <jrose at openjdk.org> wrote:

> I see that, probably due to prior `java.util` contracts, a stable list or map cannot present a `toString` with unset component values.  A stable list or map uses a “canned” `toString` method that calls `get`, which must force all component values to be evaluated before the `toString` can be printed.

I also noticed this issue of `toString` eagerly setting all elements of stable collections and agree that it probably shouldn't do this. Note that all views of these collections (obtained via `List.subList`, `List.reversed`, `Map.entrySet`, `Map.values`, etc.) would also need their own `toString` implementation.

> Just as `WeakHashMap` bends the `Map` API (regarding `equals`), I think `StableValue` composites should bend the `List` and `Map` APIs, regarding `toString`.  Sometimes the contracts have to be bent for the whole design to fit together.

Neither `List`, `Set`, nor `Map` mention any requirements for `toString` in their interface specification. Only `AbstractCollection` and `AbstractMap` have a default implementation of `toString`. So I don't think any contract would be bent here.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23972#issuecomment-2727837224


More information about the core-libs-dev mailing list