On Fri, 15 Apr 2022 05:58:32 GMT, liach <d...@openjdk.java.net> wrote:

> Explicitly implement `remove` and `replace` in `IdentityHashMap` to compare 
> values by identity. Updated API documentation of these two methods 
> ([Preview](https://cr.openjdk.java.net/~liach/8178355/IdentityHashMap.html#remove(java.lang.Object,java.lang.Object)))
>  to mention such behavior.

src/java.base/share/classes/java/util/IdentityHashMap.java line 1163:

> 1161:         public boolean remove(Object o) {
> 1162:             return o instanceof Entry<?, ?> entry
> 1163:                     && IdentityHashMap.this.remove(entry.getKey(), 
> entry.getValue());

I would prefer to keep the internal `removeMapping` method and have other 
methods call it, instead of calling a public method. In particular the 
`EntrySet.remove()` method here should call an internal method to perform the 
actual removal instead of calling the public `remove()` method, since that 
potentially exposes the "self-use" to subclasses. The the public `remove()` 
method on IDHM could call `removeMapping`.

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

PR: https://git.openjdk.java.net/jdk/pull/8259

Reply via email to