添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
打酱油的小蝌蚪  ·  在 Visual Studio Code ...·  2 月前    · 
热心的楼梯  ·  匹配PostgreSQL ...·  5 月前    · 
讲道义的鞭炮  ·  com.android.support:ap ...·  5 月前    · 
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 ----------