RFR: 8369129: Raster createPackedRaster methods specification clean up [v4]

Phil Race prr at openjdk.org
Tue Oct 14 17:48:10 UTC 2025


On Tue, 14 Oct 2025 17:43:56 GMT, Phil Race <prr at openjdk.org> wrote:

>> src/java.desktop/share/classes/java/awt/image/Raster.java line 310:
>> 
>>> 308:             throw new IllegalArgumentException("size too large to store image");
>>> 309:         }
>>> 310:         int size = (int)lsz;
>> 
>> Isn't it strange that in this method we reject "empty" images by requiring w and h to be greater than 0, but at the same time accept 0 as scanlineStride and pixelStride? This may result in empty image as well (size == 0), I think it will be rejected later but still should we check it here as well?
>
> We seem to have a number of APIs that allow the strides to be zero.
> I find them odd, but I don't see how they can cause an empty image and they need careful consideration before changing. It seems very deliberate.
> Here's a sampling of other cases (there are likely more, I searched very briefly and crudely)
> 
> 
>      * @throws IllegalArgumentException if {@code scanlineStride} is less than 0
>     public BandedSampleModel(int dataType,
>                              int w, int h,
>                              int scanlineStride,
>                              int[] bankIndices,
>                              int[] bandOffsets) 
> 
> =====
> 
>      * @throws IllegalArgumentException if {@code pixelStride} is less than 0
>      * @throws IllegalArgumentException if {@code scanlineStride} is less than 0
>   public ComponentSampleModel(int dataType,
>                                 int w, int h,
>                                 int pixelStride,
>                                 int scanlineStride,
>                                 int[] bandOffsets) {
> 
> =====
>      * @throws IllegalArgumentException if {@code pixelStride} is less than 0
>      * @throws IllegalArgumentException if {@code scanlineStride} is less than 0
>    public ComponentSampleModel(int dataType,
>                                 int w, int h,
>                                 int pixelStride,
>                                 int scanlineStride,
>                                 int[] bankIndices,
>                                 int[] bandOffsets) {

PS, also negative strides are something that we've been asked to support too - in the distant past.
But I don't have any plans to do it now.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27627#discussion_r2429982980


More information about the client-libs-dev mailing list