RFR: 8261938: ASN1Formatter.annotate should not return in the finally block [v2]

Roger Riggs rriggs at openjdk.java.net
Fri Feb 19 01:58:39 UTC 2021


On Thu, 18 Feb 2021 23:41:08 GMT, Jie Fu <jiefu at openjdk.org> wrote:

>> An EOFException can occur during the call to annotate() and must return the accumulated contents of the StringBuffer.  Otherwise it is discarded.
>
> Thanks @RogerRiggs  for your review.
> 
> Just want to make sure:
> 
>   1. AFAIK, for a method, it seems impossible to return a value and throw an exception at the same time.
>      Did you mean we just need to return a string with the IOException to be catched?
> 
>   2. Does it make sense to return a string when an IOException happens?
> 
> Thanks.

The formattters are a test component used both standalone and in the context of the HexPrinter test utilities.
In typical use, the stream is a wrapped byte array, so there are no exceptions other than EOF.
The choice of DataInputStream was chosen for the convenience of the methods to read different types
and (declared) exceptions are an unwelcome artifact.

Formatters are designed to be nested, where one formatter can call another and the valuable output
is the formatted string that has been accumulated from the beginning of the stream.  
If an exception was percolated up and the formatted output discarded it would defeat the purpose.

If an exception was thrown, it would still return useful information about the stream to that point.
The documentation could be improved to be clear on that point.

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

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


More information about the core-libs-dev mailing list