A HashMap bug with a Proxy value?
chris.hegarty at oracle.com
Wed Jan 12 16:43:02 UTC 2011
Are you referring to java.net.Proxy? Proxy.equals depends on the
resolution of its address. Address resolution could change over time,
depending on the caching policy. java.net.URL has a similar issue.
Strangely,I would have expected containsValue and containsKey to behave
in a similar fashion. I think the specification for these methods is
very clear, they should use equals(). I'm not sure if containsKey is
correct if it accepts key equality.
On 01/12/11 03:53 PM, Jing LV wrote:
> Hello everyone,
> (As I am new in OpenJDK, please tell me if I post on the wrong
> I find an odd behaviour of HashMap. If we put a value which is an
> instance of Proxy, it would return false while checking
> containsValue(proxyinstance). I checked use Proxy instance as a key, it
> works well.
> I suppose this is a bug of HashMap. By reading the code closely, I find
> the problem was that, for Proxy instance, Proxy.equals(Proxy) may return
> false (there are many discussions on this already).
> HashMap.containsKey() will check if there is a key in the map equals
> and/or the same with the given key(so it bypass equals check) with
> getEntry() method but HashMap.containsValue() does not. So a quick fix
> will be: check there is a value in the map that equals and/or the same
> with the given value.
> I'd like to report this bug to bugzilla of openjdk, with my testcase and
> patch. Please tell me if any comments. Thanks a lot.
> Best wishes!
> Jing LV
More information about the core-libs-dev