ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
baos.write(123); // does NOT have a throws-exception clause
baos.write("Hello world".getBytes()); // HAS a throws-exception clause
catch (IOException e)
// even though it never happens
JUSTIFICATION :
It's contradictive.
And it's easy to solve, without impact.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The ByteArrayOutputStream class should extend the OutputStream#write(byte[]) method and remove the exception clause:
@Override
public void write(byte b[]) // no more exception here.
try { super.write(b); } catch(IOException ioe) {}
ACTUAL -
Right now, you just always have to make an empty catch-block whenever you use this write(byte[]) method.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(byteArray);
catch (IOException ioe)
// never happens
---------- BEGIN SOURCE ----------
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(byteArray);
catch (IOException ioe)
// never happens
---------- END SOURCE ----------