JDK-6596600 : JCK Color.createContext() test cases failing in JDK 7 b14
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-08-23
  • Updated: 2017-05-19
  • Resolved: 2009-05-06
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 b27Fixed OpenJDK6Fixed
Related Reports
Relates :  
Relates :  
Description
This is a failure introduced by the fix
6530420: remove unnecessary fields in Color class
The javadoc for Color.createContext(ColorModel cm, Rectangle r,
  Rectangle2D r2d, AffineTransform xform,  RenderingHints hints)

states

          * The same <code>PaintContext</code> is returned, regardless of
1166      * whether or not <code>r</code>, <code>r2d</code>,
1167      * <code>xform</code>, or <code>hints</code> are <code>null</code>.

A JCK test apparently tests for this by creating contexts which differ
in small ways, such as passing in a Rectangle in one case, and null in the other,
similar to this code :
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;

public class tc4 {
   public static void main(String args[]) {
        float[] cp =  { 0.5f, 0.5f, 0.5f, 0.5f };
        ColorModel cm = ColorModel.getRGBdefault();
        Rectangle r = new Rectangle(0, 0, 200, 200);
        Rectangle2D.Float r2d = new Rectangle2D.Float(0f, 0f, 100f, 100f);
        AffineTransform af = new AffineTransform();
        Color c = new Color(cp[0], cp[1], cp[2], cp[3]);
        PaintContext pContext1 = c.createContext(cm, null, r2d, af,
                new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT));
        PaintContext pContext2 = c.createContext(cm, r, r2d, af,
                new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT));
        System.out.println(pContext1.equals(pContext2));
   }
}

Prior to 1.7 b14 this would print "true" now it prints "false"
The reason for this is that previously the code "cached" a PaintContext.
Now it always returns a new instance, which would be "equal" except that
the implementing class does not over-ride equals.
Also the text "the same PaintContext" is not specific as to whether it means
"equal" or the stronger "==".

There is also the question of the "cm" parameter. Although the test uses the
same "cm" parameter, it seems a bit odd and unreasonable to expect that the
Color instance caches a PaintContext for each ColorModel, so as to always
return the same instance. However a strict reading of the spec might require this.

But in practice this doesn't matter as although the "cm" instance is passed
to the constructor of the class which implements PaintContext, that class
discards it. So in fact you really do always get equivalent PaintContext
instances regardless of the cm parameter.

Perhaps the most pragmatic way to resolve this is for the PaintContext
to override equals, but it would be good to also update the doc to
use the word "equal" rather than "the same".

Comments
SUGGESTED FIX http://ccc.sfbay/6573289
04-04-2008

EVALUATION The change in behavior was intentional and we did not notice that the caching was documented when we made the change. The change is important for performance reasons so we plan to simply eliminate the text from the doc comments for the createContext() method and file the appropriate change requests as needed. This work is being persued by the AWT team under bug 6573289. I am closing this bug as a duplicate of 6573289.
25-08-2007