Name: dk106046 Date: 05/14/2003
JDK: 1.3.1, 1.4, 1.4.1.
Exact Steps to Reproduce:
The problem is intermittent / timing related
Run any code that calls causes ColorSpace.getInstance to be called
from multiple threads, and it will happen eventually.
Exact Text of error message:
java.awt.color.CMMException: Invalid profile data
java/lang/Throwable.<init>(Ljava/lang/String;)V+4
(Throwable.java:90)
java/lang/Exception.<init>(Ljava/lang/String;)V+1
(Exception.java:38)
java/lang/RuntimeException.<init>(Ljava/lang/String;)V+1
(RuntimeException.java:43)
sun/awt/color/CMM.checkStatus(I)V+12 (CMM.java:121)
java/awt/color/ICC_ColorSpace.toRGB([F)[F+50
(ICC_ColorSpace.java:142)
java/awt/image/DirectColorModel.getRGB(I)I+7
(DirectColorModel.java:399)
Code fix for JDK:
Synchronize the code marked >>> synchronize <<< end synchronize.
Potentially synchronize the whole getInstance method as the other
elements of the case have the same logic (although have not seen
actual bug happen).
public static ColorSpace getInstance (int colorspace)
{
ColorSpace theColorSpace;
switch (colorspace) {
case CS_sRGB:
>>> synchronize
if (sRGBspace == null) {
ICC_Profile theProfile = ICC_Profile.getInstance (CS_sRGB);
sRGBspace = new ICC_ColorSpace (theProfile);
}
theColorSpace = sRGBspace;
<<< End synchronize
break;
case CS_CIEXYZ:
if (XYZspace == null) {
ICC_Profile theProfile = ICC_Profile.getInstance
(CS_CIEXYZ);
XYZspace = new ICC_ColorSpace (theProfile);
}
theColorSpace = XYZspace;
break;
case CS_PYCC:
if (PYCCspace == null) {
ICC_Profile theProfile = ICC_Profile.getInstance (CS_PYCC);
PYCCspace = new ICC_ColorSpace (theProfile);
}
theColorSpace = PYCCspace;
break;
case CS_GRAY:
if (GRAYspace == null) {
ICC_Profile theProfile = ICC_Profile.getInstance (CS_GRAY);
GRAYspace = new ICC_ColorSpace (theProfile);
}
theColorSpace = GRAYspace;
break;
case CS_LINEAR_RGB:
if (LINEAR_RGBspace == null) {
ICC_Profile theProfile =
ICC_Profile.getInstance(CS_LINEAR_RGB);
LINEAR_RGBspace = new ICC_ColorSpace (theProfile);
}
theColorSpace = LINEAR_RGBspace;
break;
default:
throw new IllegalArgumentException ("Unknown color space");
}
return theColorSpace;
}
The JDK 1.4.1 version of java/awt/color/ColorSpace.java appears to have
exactly the same problem. Note also, that
java/awt/color/ICC_Profile.getInstance(int cspace) in both JDK 1.3.1 and
1.4.1 has the same potential multiple creation problem, but I have not yet
observed it to actually cause an observable problem if synchronization has
been implemented in ColorSpace.getInstance.
======================================================================