RFR: 8300929: Avoid unnecessary array fill after creation in java.awt.image
Andrey Turbanov
aturbanov at openjdk.org
Tue Jan 24 18:27:16 UTC 2023
On Tue, 24 Jan 2023 16:22:43 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> No need to fill elements of array with default values if it was just created. Java guarantees that all elements of numeric array have default values after allocations - 0.
>
> src/java.desktop/share/classes/java/awt/image/ComponentColorModel.java line 521:
>
>> 519: {
>> 520: byte[] bpixel = new byte[numComponents];
>> 521: for (int i = 0; i < numColorComponents; i++) {
>
> Is it possible that indirectly this code threw the AIOBE for some wrong "numColorComponents"?
I believe it's impossible to get AIOBE here (at least without some reflection tricks).
`numColorComponents` and `numComponents` are assigned only in 2 places. And in both places it's guarantee that `numComponents >= numColorComponents`

-------------
PR: https://git.openjdk.org/jdk/pull/12147
More information about the client-libs-dev
mailing list