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)

Reply via email to