-
Enhancement
-
Resolution: Fixed
-
P4
-
8, 9
-
b07
A DESCRIPTION OF THE REQUEST :
ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
baos.write(123); // does NOT have a throws-exception clause
try
{
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();
try
{
baos.write(byteArray);
}
catch (IOException ioe)
{
// never happens
}
---------- BEGIN SOURCE ----------
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
baos.write(byteArray);
}
catch (IOException ioe)
{
// never happens
}
---------- END SOURCE ----------
ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
baos.write(123); // does NOT have a throws-exception clause
try
{
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();
try
{
baos.write(byteArray);
}
catch (IOException ioe)
{
// never happens
}
---------- BEGIN SOURCE ----------
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
baos.write(byteArray);
}
catch (IOException ioe)
{
// never happens
}
---------- END SOURCE ----------
- csr for
-
JDK-8199713 ByteArrayOutputStream should not throw IOExceptions
-
- Closed
-
- relates to
-
JDK-8180451 ByteArrayInputStream should override readAllBytes, readNBytes, and transferTo
-
- Resolved
-
-
JDK-4787155 ByteArrayOutputStream.write(byte[]) should not throw IOException
-
- Closed
-
-
JDK-8187898 PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
-
- Resolved
-
- links to