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.burkhal...@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.giulie...@gmail.com <mailto:raffaello.giulie...@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"); >> + }