--- old/src/java.desktop/share/classes/java/awt/image/PackedColorModel.java 2016-07-20 22:17:17.140921472 +0530 +++ new/src/java.desktop/share/classes/java/awt/image/PackedColorModel.java 2016-07-20 22:17:16.940921472 +0530 @@ -27,6 +27,7 @@ import java.awt.Transparency; import java.awt.color.ColorSpace; +import java.util.Arrays; /** * The {@code PackedColorModel} class is an abstract @@ -88,6 +89,7 @@ int[] maskArray; int[] maskOffsets; float[] scaleFactors; + private volatile int hashCode; /** * Constructs a {@code PackedColorModel} from a color mask array, @@ -385,19 +387,25 @@ } /** - * Tests if the specified {@code Object} is an instance - * of {@code PackedColorModel} and equals this + * Tests if the specified {@code Object} equals this * {@code PackedColorModel}. + * In order to protect the symmetry property of + * {@code (a.equals(b) == b.equals(a))}, + * the target object must be the same class (and not a subclass) + * as this object to evaluate as {@code equals}. + * The target object and this object will be equal if and only if + * {@link ColorModel#equals()} returns true and the masks + * of the color and alpha samples are the same. * @param obj the {@code Object} to test for equality * @return {@code true} if the specified {@code Object} - * is an instance of {@code PackedColorModel} and equals this - * {@code PackedColorModel}; {@code false} otherwise. + * equals this {@code PackedColorModel}; {@code false} otherwise. */ + @Override public boolean equals(Object obj) { - if (!(obj instanceof PackedColorModel)) { - return false; - } - + /* + * We verify the type of argument obj in super.equals() where we check + * for equality of class name. + */ if (!super.equals(obj)) { return false; } @@ -412,6 +420,22 @@ return true; } + /** + * Returns the hash code for this PackedColorModel. + * + * @return a hash code for this PackedColorModel. + */ + @Override + public int hashCode() { + int result = hashCode; + if (result == 0) { + result = super.hashCode(); + result = 89 * result + Arrays.hashCode(this.maskArray); + hashCode = result; + } + return result; + } + private static final int[] createBitsArray(int[]colorMaskArray, int alphaMask) { int numColors = colorMaskArray.length;