On 2021-06-27, Gilles Sadowski wrote:

> Le dim. 27 juin 2021 à 21:15, Stefan Bodewig <bode...@apache.org> a écrit :

>> As I said, we can as well document that each method could throw
>> arbitrary RuntimeExceptions, but I don't believe we can list the kinds
>> of RuntimeExceptions exhaustively

> Why not?
> Listing all runtime exceptions is considered part of good
> documentation.

Because we do not know which RuntimeExceptions may be caused by an
invalid archive.

Most of the RuntimeException happen because our parsers believe in a
world where every archive is valid. For example we may read a few bytes
that are the size of an array and then create the array without checking
whether the size is negative and a NegativeArraySizeException occurs.

As we haven't considered the case of a negative size in code, we also do
not know this exception could be thrown. If we had considered the case
of negative sizes, the parser could have avoided the exception
alltogether. This is what I meant with

>> - if we knew which exceptions can be thrown, then we could as well
>> check the error conditions ourselves beforehand.

Our parsers could of course be hardened, but this is pretty difficult to
do years after they've been written and would certainly miss a few
corner cases anyway.

And then there is a certain category of exceptions thrown by Java
classlib methods we invoke. We've just added a catch block around
java.util.zip.ZipEntry#setExtra because certain invalid archives cause a
RuntimeException there - and if I remember correctly a RuntimeException
the method's javadoc doesn't list.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to