JDK-4559156 : java.awt.Color.equals() does not work when comparing to java.awt.SystemColor
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-12-08
  • Updated: 2010-07-09
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b02Fixed
Related Reports
Relates :  
Relates :  
Description
Name: gm110360			Date: 12/07/2001


java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

When you compare two colors for equality using equals( Object obj ) the test
will likely fail if one of the colors is java.awt.Color and one is
java.awt.SystemColor.  Because SystemColor extends Color, you might think equals
would work.  Here is the code from Color:

public boolean equals(Object obj) {
    return obj instanceof Color && ((Color)obj).value == this.value;
}

The problem is that value is the rgb value in Color.  In SystemColor value is
the index to the color table in systemColors.
(Review ID: 134033) 
======================================================================

Comments
EVALUATION The problem disappearing with the fix for 6389283. There we started to use SystemColor.value as Color RGB representation instead of index in array. See comments for a draft of regression test.
17-05-2006

EVALUATION Specification for equals() is not clear about acceptable value type. If we fix this CR then we should clarify documentation too.
06-12-2005

WORK AROUND Name: gm110360 Date: 12/07/2001 Use getRGB() instead. ======================================================================
17-09-2004