RFR: 8245036: DataInputStream.readFully(byte[], int, int) does not throw expected IndexOutOfBoundsExceptions

Brian Burkhalter brian.burkhalter at oracle.com
Wed Aug 5 16:24:36 UTC 2020


Also, instead of using the boolean “caughtException,” we usually just put, e.g., the throwing of the RuntimeException on the line after where the IIOBE or whatever would be thrown. I don’t think the “finally” block is necessary.

Thanks,

Brian

> On Aug 5, 2020, at 9:20 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
> 
> HI Raffaello,
> 
> The implementation test looks right. In the test, you might consider using try-with-resources.
> 
> Thanks,
> 
> Brian
> 
>> On Jul 29, 2020, at 10:44 AM, Raffaello Giulietti <raffaello.giulietti at gmail.com <mailto:raffaello.giulietti at gmail.com>> wrote:
>> 
>> +        FileInputStream in = new FileInputStream(file);
>> +        DataInputStream dis = new DataInputStream(in);
>> +
>> +        boolean caughtException = false;
>> +        try {
>> +            dis.readFully(buffer, -1, buffer.length);
>> +        } catch (IndexOutOfBoundsException ie) {
>> +            caughtException = true;
>> +        } finally {
>> +            dis.close();
>> +            if (!caughtException)
>> +                throw new RuntimeException("Test testNegativeOffset() failed");
>> +        }



More information about the core-libs-dev mailing list