-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P2
-
Affects Version/s: 17, 21, 25, 26, 27
-
Component/s: client-libs
-
b08
from spec of
java.awt.image.Raster.createBandedRaster(int dataType, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location),
we have:
IllegalArgumentException – if scanlineStride is less than 0.
However, when I tried large negative values such as -1000 or Integer.MIN_VALUE, I encountered a java.lang.NegativeArraySizeException instead of the expected IllegalArgumentException.
Code Example:
void main(String[] args) {
int scanlineStride = -100;
int[] bankIndices = {0, 1, 2};
int[] bandOffsets = {0, 0, 0};
WritableRaster.createBandedRaster(
DataBuffer.TYPE_BYTE,
2, // width
2, // height
scanlineStride,
bankIndices,
bandOffsets,
new Point(0, 0)
);
}
After reviewing the OpenJDK code, I noticed that the exception is thrown before execution reaches the check for scanlineStride < 0. Specifically, it occurs in the following block:
case DataBuffer.TYPE_BYTE:
d = new DataBufferByte(size, banks);
break;
As a result, the documented exception behavior is not consistently enforced for all negative values of scanlineStride.
I think this warrants a documentation enhancement to clarify the actual behavior.
Spec (Java SE 27 ) : https://download.java.net/java/early_access/jdk27/docs/api/java.desktop/java/awt/image/Raster.html#createBandedRaster(int,int,int,int,int%5B%5D,int%5B%5D,java.awt.Point)
java.awt.image.Raster.createBandedRaster(int dataType, int w, int h, int scanlineStride, int[] bankIndices, int[] bandOffsets, Point location),
we have:
IllegalArgumentException – if scanlineStride is less than 0.
However, when I tried large negative values such as -1000 or Integer.MIN_VALUE, I encountered a java.lang.NegativeArraySizeException instead of the expected IllegalArgumentException.
Code Example:
void main(String[] args) {
int scanlineStride = -100;
int[] bankIndices = {0, 1, 2};
int[] bandOffsets = {0, 0, 0};
WritableRaster.createBandedRaster(
DataBuffer.TYPE_BYTE,
2, // width
2, // height
scanlineStride,
bankIndices,
bandOffsets,
new Point(0, 0)
);
}
After reviewing the OpenJDK code, I noticed that the exception is thrown before execution reaches the check for scanlineStride < 0. Specifically, it occurs in the following block:
case DataBuffer.TYPE_BYTE:
d = new DataBufferByte(size, banks);
break;
As a result, the documented exception behavior is not consistently enforced for all negative values of scanlineStride.
I think this warrants a documentation enhancement to clarify the actual behavior.
Spec (Java SE 27 ) : https://download.java.net/java/early_access/jdk27/docs/api/java.desktop/java/awt/image/Raster.html#createBandedRaster(int,int,int,int,int%5B%5D,int%5B%5D,java.awt.Point)
- links to
-
Commit(master)
openjdk/jdk/69c868d5
-
Review(master)
openjdk/jdk/29454