curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Blum <>
Subject NamespaceWatcher hashCode and equals still bugging me
Date Tue, 09 Feb 2016 16:49:24 GMT
Hi guys,

I'm a practical guy, not a purist, but the 3.0 implementations of
NamespaceWatcher.hashCode() and equals() are bothering me.  The reason I
care is that I want to avoid subtle bugs cropping up.

So here's the problem.

1) equals() is not reflexive between NamespaceWatcher and Watcher

Assuming you have a NamespaceWatcher nw wrapping a Watcher w, the following
code might or might not work:


It depends on whether the underlying container ultimately does
"nw.equals(w)" or "w.equals(nw)".  Set.contains() would have the same

2) hashCode() and equals() inconsistent with each other

Because nw.hashCode() != w.hashCode(), lookups in a hashSet or hashMap will
practically never work except by luck.


Most of the time this will return false, except in the exact case where nw
and w happen to have hashCodes that map into the same bucket, and the
equality check is done the "right" order.

So.... taking a step back, what was underlying motivation for the hashCode
/ equality changes?  IE, what's the bigger problem we were trying to solve?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message