Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
-
Patch
Description
In src/main/java/org/apache/commons/bcel6/generic/InstructionList.java
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];
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.