RFR: 8272998: ImageIO.read() throws incorrect exception type

Phil Race prr at openjdk.org
Tue Jun 21 18:28:13 UTC 2022


On Thu, 16 Jun 2022 03:29:24 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

>> ImageIO.read() only documents IOException for any kind of decoding problem and since
>> it is a convenience API we don't want to start requiring applications to handle other RuntimeExceptions.
>> So in the unlikely case of some problem decoding using this API, wrap any RuntimeException in
>> an IIOException. This will give more stable app behaviour and still report the underlying problem.
>
> src/java.desktop/share/classes/javax/imageio/ImageIO.java line 1467:
> 
>> 1465:         try (stream) {
>> 1466:             bi = reader.read(0, param);
>> 1467:         } catch (RuntimeException e) {
> 
> Is that necessary to catch all possible runtime exceptions? Probably we should catch only the exceptions thrown by the read method? I think it should be "IllegalArgumentException" only, the IllegalStateException/IndexOutOfBoundsException should not be thrown here, and the IOException is fine.

I did comment on this in the bug and the PR description.
Other exception types are possible or very difficult to prove they won't be thrown anprop if it ever did happen
we'd be back here. So this seems like the best to thing to do since we do not want to propagate them.

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

PR: https://git.openjdk.org/jdk/pull/9113



More information about the client-libs-dev mailing list