JDK-6389283 : SystemColor.createContext(..) - is it correct? is it needed?
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2006-02-23
  • Updated: 2017-05-16
  • 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 Other
7 b02Fixed OpenJDK6Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
SystemColor.createContext(..) currently overrides the same method in java.awt.Color 
by removing caching of the PaintContext instance. This breaks the subclassing contract
and most likely is a mistake: originally, there was no caching in java.awt.Color either;
at some point it was added, but not propagated to SystemColor.

Also, both Color and SystemColor use 'new ColorPaintContext(value, cm)'. However, 'value' 
is the RGB value for Color, and an *index* into the array of RGB values for SystemColor.
This doesn't look right.

Comments
EVALUATION Previous explanation uncovered a serious problem I tried to solve. First I made indexValue non-transient. This make access to it in SystemColor.readObject(). This method works fine if object deserializes from old JDK version and from current one. The problem arises if we serialize SystemColor and then try to deserialize it on previous version of JDK. In that case Color.writeObject() starts first and writes "value" variable so SystemColor doesn't write it. This breaks restored class as it now contains integer representation of color in the "value" field. Although it's correctly it wouldn't look good with previous releases. The only approach is to check actual instance in Color.writeObject() but it's really doesn't look good. I tried to look for other way and seem writeReplace() does the thing we need! Implemented and tried to ser|deserialize SystemColor in both directions and it does works.
13-03-2006

EVALUATION It is important to note that the system color palette can change dynamically. See awt_Toolkit.cpp where it calls updateSystemColors() when it receives a SYSCOLORCHANGE event from the Window operating system. The reason an index value is used as the color value here is so that these objects can react to the dynamically changing color palette. When the colors change, only the array of color values is updated, all existing SystemColor objects have already been created. If they are to react to the change, then they need to refer back to that array in 3 places - getRGB() and createContext() and after deserialization. The proposed fix would eliminate that back reference and lock in the color to the value it had when the object was created. If caching is desired then the value in the array of color values should be tested for changes before a cached ColorContext is reused.
12-03-2006

SUGGESTED FIX http://ccc.sfbay/6389283
07-03-2006

EVALUATION Using index value as color in createContext() might be considered like mistake and perhaps wasn't uncover due to a restricted class usage. I'd suggest just fix that mistake and leave createContext() in that class.
06-03-2006

SUGGESTED FIX http://sa.sfbay.sun.com/projects/awt_data/dolphin/6389283.1/
06-03-2006

EVALUATION According to the history file SystemColor.createContext() has been added (delta 1.8) before changes Color.createContext() took place (delta 1.33). Although there is no good description for these changes in SystemColor but seems these methods should do the same. This fix requires CCC approve.
26-02-2006

EVALUATION This class is owned by AWT.
23-02-2006

SUGGESTED FIX Remove this method. This should have very little (if any) backward compatibility impact as the effectively same functionality would be inherited from the parent. *** (#1 of 1): [ UNSAVED ] ###@###.###
23-02-2006