On Wed, 9 Apr 2025 18:05:37 GMT, Jeremy Wood <d...@openjdk.org> wrote:

>> 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.)

I missed that `byteOut` was declared inside the try-block only. More in [the 
following 
comment](https://github.com/openjdk/jdk/pull/23920#discussion_r2036131572), 
which I should've posted as a reply to this thread.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23920#discussion_r2036150901

Reply via email to