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

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


On Fri, 10 Oct 2025 05:21:19 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

>> Phil Race has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8369129
>
> 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) {

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

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


More information about the client-libs-dev mailing list