-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta2
-
generic
-
generic
-
Not verified
Name: vpR10011 Date: 04/20/2001
Specification of the class javax.imageio.stream.ImageOutputStreamImpl says:
"public void writeBits(long bits, int numBits) throws IOException
...
Parameters:
bits - a long containing the bits to be written, starting with the bit in
position numBits - 1 down to the least signficant bit.
^^ typo copied from the spec.
numBits - an int between 0 and 64, inclusive.
Throws:
IllegalArgumentException - if numBits is not between 0 and 64,
inclusive.
IOException - if an I/O error occurs."
But writeBits does not throw any exception if numBits is not between 0 and 64.
To reproduce this bug run the following test:
---------------------test.java--------------
import java.io.*;
import javax.imageio.stream.*;
public class test {
public static void main(String[] argv) {
OutputStream os = (OutputStream) new ByteArrayOutputStream();
ImageOutputStreamImpl iosI = (ImageOutputStreamImpl) new MemoryCacheImageOutputStream(os);
System.out.println("numbits < 0");
try {
iosI.writeBits(1L, -1);
System.out.println("Failed: IllegalArgumentException was expected");
} catch (IllegalArgumentException e) {
System.out.println("Passed");
} catch (Exception e) {
System.out.println("Failed: unexpected exception " + e);
}
System.out.println("numbits > 64");
try {
iosI.writeBits(1L, 100);
System.out.println("Failed: IllegalArgumentException was expected");
} catch (IllegalArgumentException e) {
System.out.println("Passed");
} catch (Exception e) {
System.out.println("Failed: unexpected exception " + e);
}
}
}
-------------------------log----------------
% java -version
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b60)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)
% java test
numbits < 0
Failed: IllegalArgumentException was expected
numbits > 64
Failed: IllegalArgumentException was expected
This bug causes failure of the new JCK test
api/javax_imageio/stream/ImageOutputStreamImpl/index.html#write
======================================================================