-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta2
-
generic
-
generic
Name: bkR10012 Date: 03/28/2001
Spec. of the class javax.imageio.ImageTypeSpecifier says:
"ImageTypeSpecifier
public ImageTypeSpecifier(ColorModel colorModel,
SampleModel sampleModel)
Constructs an ImageTypeSpecifier directly from a ColorModel and a SampleModel.
It is the caller's responsibility to supply compatible parameters."
But if parameters are incompatible it leads to throwing unexpected exceptions
in other methods.
For example, method
'public BufferedImage createBufferedImage(int width, int height)'
throws unexpected IllegalArgumentException.
My proposal is: ImageTypeSpecifier constructor should throw
IllegalArgumentException if colorModel and sampleModel are incompatible.
In other case, all possible exceptions in methods which use imageTypeSpecifier
should be specified.
See test source and log below.
---------------------------------------- test.java
package test;
import javax.imageio.ImageTypeSpecifier;
import java.awt.image.SampleModel;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
public class test {
public static void main(String argv[]) {
ImageTypeSpecifier itspecifier;
int bits = 32;
int rmask = 0x00ff0000;
int gmask = 0x0000ff00;
int bmask = 0x000000ff;
ColorModel dcm = new java.awt.image.DirectColorModel
(bits, rmask, gmask, bmask);
int[] bandOffsets = new int[2];
bandOffsets[1] = 1;
SampleModel sm = new java.awt.image.ComponentSampleModel
(DataBuffer.TYPE_SHORT, 1, 1, 2, 2, bandOffsets);
itspecifier = new ImageTypeSpecifier( dcm, sm);
itspecifier.createBufferedImage(5, 5);
System.out.println("END");
}
}
----------------------------------------
% java -version
java version "1.4.0-internal"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-internal-b57)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b57, mixed mode)
% java test.test
Exception in thread "main" java.lang.IllegalArgumentException: Raster
java.awt.image.WritableRaster@439a2d is incompatible with ColorModel
DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
at java.awt.image.BufferedImage.<init>(BufferedImage.java:519)
at
javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:978)
at test.test.main(test.java:25)
----------------------------------------
This bug causes failure of the new JCK test
api/javax_imageio/ImageTypeSpecifier/index.html#createBufferedImage
======================================================================