RFR: 8328821: Map.of() derived view collection mutators should throw UnsupportedOperationException

Chen Liang liach at openjdk.org
Tue Jul 9 22:26:17 UTC 2024


On Fri, 26 Apr 2024 18:20:18 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

>> This change overrides mutator methods in the implementation returned by `Map.of().entrySet()` to throw `UnsupportedOperationException`.
>
> Please keep this open

@cushon Given we have specified in `Collection` that unmodifiability extends to all derived collection views: https://github.com/openjdk/jdk/blob/4c9a511f75174a3f3ae575fae2677c198c607b52/src/java.base/share/classes/java/util/Collection.java#L159-L160

Would you mind changing "Calling any mutator method on the Map will ..." to something like "... on the map or any derived view collection will ..." to emphasize our new consistency? (Our internal conversation agreed on this)
https://github.com/openjdk/jdk/blob/4c9a511f75174a3f3ae575fae2677c198c607b52/src/java.base/share/classes/java/util/Map.java#L125-L126

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

PR Comment: https://git.openjdk.org/jdk/pull/18522#issuecomment-2218833548


More information about the core-libs-dev mailing list