Uploaded image for project: 'Commons BCEL'
  1. Commons BCEL
  2. BCEL-269

Flushing DataOutputStream before calling toByteArray on the underlying ByteArrayOutputStream

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 6.0
    • 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.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            emopers emopers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment