On Mon, 20 Apr 2026 16:32:22 GMT, Phil Race <[email protected]> wrote:
>> The bug was filed to note that the constructor for >> MultiPixelPackedSampleModel could throw an odd exception if numberOfBits is >> zero. >> Per the spec this should throw RasterFormatException. >> >> >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Phil Race has updated the pull request incrementally with one additional > commit since the last revision: > > 8381007 src/java.desktop/share/classes/java/awt/image/MultiPixelPackedSampleModel.java line 107: > 105: * is not a power of 2 or if a power of 2 number of > 106: * pixels do not fit in one data element. > 107: */ These exceptions are not new, but the spec omitted them. src/java.desktop/share/classes/java/awt/image/MultiPixelPackedSampleModel.java line 146: > 144: * @throws RasterFormatException if > 145: * {@code (numberOfBits * w) / > DataBuffer.getDataTypeSize(dataType)} > 146: * is greater than {@code scanlineStride} Looks like more changed than really did because I re-arranged the order. This exception for scanlineStride is the "new" exception here (so is all that will be in the CSR) I don't see how it could be legal to have a scan line stride that isn't large enough. Some of the code in the class that indexes multiplies by this, so we should enforce it. src/java.desktop/share/classes/java/awt/image/MultiPixelPackedSampleModel.java line 151: > 149: * pixels do not fit in one data element. > 150: * @throws IllegalArgumentException if {@code dataBitOffset} is less > than zero, > 151: * or not a multiple of {@code numberOfBits}. The class doc already says this, however it was not explicitly checked. It has to be a requirement, else pixels would span data elements, which is absolutely not allowed. src/java.desktop/share/classes/java/awt/image/MultiPixelPackedSampleModel.java line 164: > 162: this.dataType = dataType; > 163: if ((numberOfBits <= 0) || ((numberOfBits & (numberOfBits - 1)) > != 0)) { > 164: throw new RasterFormatException("numberOfBits per pixel must > be a power of 2"); You would have got an exception anyway for these (although 0 would have been the wrong type). This just makes it clearer that you've passed in an illegal value because it is not a power of 2, vs spanning a data element. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/30826#discussion_r3112113579 PR Review Comment: https://git.openjdk.org/jdk/pull/30826#discussion_r3112138409 PR Review Comment: https://git.openjdk.org/jdk/pull/30826#discussion_r3112194225 PR Review Comment: https://git.openjdk.org/jdk/pull/30826#discussion_r3112149793
