RFR: 8262297: ImageIO.write() method will throw IndexOutOfBoundsException [v2]

Phil Race prr at openjdk.java.net
Fri Oct 29 16:50:12 UTC 2021


On Fri, 29 Oct 2021 09:36:37 GMT, Masanori Yano <myano at openjdk.org> wrote:

>> Could you please review the 8262297 bug fixes?
>> 
>> In this case, ImageIO.write() should throw java.io.IOException rather than java.lang.IndexOutOfBoundsException. IndexOutOfBoundsException is caught and wrapped in IIOException in ImageIO.write() with this fix. In addition, IndexOutOfBoundsException is not expected to throw by RandomAccessFile#write() according to its API specification. So it should be fixed.
>
> Masanori Yano has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8262297: ImageIO.write() method will throw IndexOutOfBoundsException

I am not sure that this is the right thing at all here. You need to dig deeper.
- If Image I/O reads the png and constructs a BufferedImage, then that BufferedImage ought to be valid.
- If a valid image is written I would NOT expect an exception so catching it isn't the answer, fixing it is.

- If the image being read is "truncated" so that the BufferedImage isn't valid, why was there no exception from read ?
- If we do have an invalid BufferedImage then, in that case, we may indeed expect that write might throw an exception which needs to be caught but IIOBE is just one thing that could go wrong, isn't it ?

So for me this starts with the read, and a proper explanation of what happens there, and then an explanation as to what is wrong with the BufferedImage. I have no interest in slapping a sticking plaster on the observed symptom. It needs to be root cause explained and fixed.

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

PR: https://git.openjdk.java.net/jdk/pull/6151



More information about the client-libs-dev mailing list