You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "emopers (JIRA)" <ji...@apache.org> on 2016/02/05 05:04:39 UTC
[jira] [Created] (BCEL-269) Flushing DataOutputStream before
calling toByteArray on the underlying ByteArrayOutputStream
emopers created BCEL-269:
----------------------------
Summary: Flushing DataOutputStream before calling toByteArray on the underlying ByteArrayOutputStream
Key: BCEL-269
URL: https://issues.apache.org/jira/browse/BCEL-269
Project: Commons BCEL
Issue Type: Bug
Reporter: emopers
Priority: Minor
In src/main/java/org/apache/commons/bcel6/generic/InstructionList.java
{code}
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try {
for (InstructionHandle ih = start; ih != null; ih = ih.getNext()) {
Instruction i = ih.getInstruction();
i.dump(out); // Traverse list
}
} catch (IOException e) {
System.err.println(e);
return new byte[0];
{code}
When a DataOutputStream instance wraps an underlying ByteArrayOutputStream instance,
it is recommended to flush or close the DataOutputStream before invoking the underlying instances's toByteArray(). Also, it is a good practice to call flush/close explicitly as mentioned for example http://stackoverflow.com/questions/2984538/how-to-use-bytearrayoutputstream-and-dataoutputstream-simultaneously-java.
The patch is to add flush method before calling toByteArray.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)