On Tue, 4 Nov 2025 01:12:07 GMT, Sergey Bylokhov <[email protected]> wrote:
>> I've played around a bit.
>> Commenting specifically about the one createInterleavedRaster factory method
>> which accepts, width, height and the strides, I don't think such cases of
>> zero pixel stride have ever been useful.
>> I've written a small test (which I'll paste below) and as far as I've found
>> so far, a zero pixel or scan line stride always results in an exception
>> from somewhere. And the exceptions are the same for each case. I've tried
>> JDK 8, JDK 24 and a build of the current proposed fix.
>>
>> So I think we could explicitly disallow 0 for these strides on this method
>> although rather than a mix
>> of RasterFormatException and IllegalArgumentException, they'd all become
>> IllegalArgumentException
>>
>> For the other public factory method createInterleavedRaster that accepts a
>> DataBuffer, even if the app makes it large enough,
>> there's still an exception in most cases. The sole "working" case I've found
>> is if bandoffsets are also all zero.
>>
>> Raster.createInterleavedRaster(new DataBufferByte(100), 1, 1, 0, 0, new
>> int[] { 0 });
>>
>> To continue to allow that we'd need to still allow zero strides on that
>> method and use words about the bandoffsets.
>>
>> The words about the bandOffsets should in fact go on both methods. They
>> apply more broadly than a zero stride.
>>
>> I'll proceed accordingly unless you spot an issue. Also I'll need to run all
>> our tests which I've not done yet.
>>
>> I don't intend to look at the allowability of zero in other APIs as part of
>> this change.
>>
>> BTW negative strides was asked for here :
>> https://bugs.openjdk.org/browse/JDK-4296691
>>
>> I don't think we'll ever do that.
>>
>> test program :
>> import static java.awt.image.DataBuffer.TYPE_BYTE ;
>> import java.awt.image.Raster;
>>
>> public class ZeroStride {
>> public static void main(String[] args) {
>> // w h ss ps bandoffsets
>> test(1, 1, 0, 0, new int[] { 0, 0, 0});
>> test(1, 1, 0, 0, new int[] { 0, 1, 2});
>> test(1, 1, 0, 1, new int[] { 0, 0, 0});
>> test(1, 1, 3, 0, new int[] { 0, 0, 0});
>> test(1, 1, 3, 0, new int[] { 0, 1, 2});
>> }
>>
>> static void test(int w, int h, int scanlineStride, int pixelStride,
>> int[] offsets) {
>> try {
>> System.err.println("w="+w+" h=" + h + " scanlineStride=" +
>> scanlineStride +
>> " pixelStride = " + pixelStride +
>> ((offsets[1] == 0) ? " bands={0,0,0}" : "
>> bands={0,1,2}"));
>> ...
>
>>I'll proceed accordingly unless you spot an issue. Also I'll need to run all
>>our tests which I've not done yet.
>
> all tests are green?
Yes all tests are green.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27627#discussion_r2547806650