RFR: 8351110: ImageIO.write for JPEG can write corrupt JPEG for certain thumbnail dimensions [v7]
Jeremy Wood
duke at openjdk.org
Wed Apr 9 18:09:34 UTC 2025
On Wed, 9 Apr 2025 17:03:26 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:
>> Jeremy Wood has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 8351913: code cleanup
>>
>> This is in response to:
>> https://github.com/openjdk/jdk/pull/23920#discussion_r2029297962
>
> test/jdk/javax/imageio/plugins/jpeg/WriteJPEGThumbnailTest.java line 86:
>
>> 84: thumbnail = writeImage(byteOut);
>> 85: jpegData = byteOut.toByteArray();
>> 86: }
>
> For `ByteArrayOutputStream`, it should be okay to convert it before the stream is closed, and the stream is closed by `writeImage` anyway. However, placing `jpegData = byteOut.toByteArray()` after the try-with-resources for `byteOut` won't raise any questions. Then, `jpegData` can be declared where it's assigned.
If I understood you correctly:
I couldn't place `jpegData = byteOut.toByteArray()` after the try-with-resources block because `byteOut` fell out of scope.
But if the priority is to declare variables where they're assigned: I can just remove that inner try-with-resources block. (This is updated.)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23920#discussion_r2035875168
More information about the client-libs-dev
mailing list