[OpenJDK 2D-Dev] Review Request for JDK-8153943 : In java.awt.image package some of the classes are missing hashCode() or equals() method

Jim Graham james.graham at oracle.com
Tue Apr 26 23:04:26 UTC 2016

On 4/25/16 8:48 AM, Sergey Bylokhov wrote:
> On 23.04.16 4:59, Jim Graham wrote:
>> So, I'd recommend that CM.equals() tests getClass() == getClass() at the
>> base level and then all others will use super.equals() and get the same
>> protection.  It means you can't have a subclass of CCM be "equals" to a
>> different subclass of CCM, but that's an unfortunate issue with equals
>> needing to honor symmetry...  :(
> Small note. In this case the custom classes which do not provide the new
> state, cannot compares to parent class because of "class==class" check.
> I guess this is behavior change, but I am not sure should we document
> that or not.

I don't believe that we have any more than single-level inheritance with 
CM objects, but just in case there are custom subclasses of these 
objects we should probably mention it.  It probably couldn't hurt to 
document it in the doc comments for the equals() classes and mention it 
in the CCC requests.  I'd suggest something like:

* Because there are multiple subclasses of ColorModel that might
* be compared against each other with this method, and in order
* to protect the symmetry property of
* {@code (a.equals(b) == b.equals(a))},
* the target object must be the exact same class as this
* object to evaluate as {equals}.


More information about the 2d-dev mailing list