You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2019/07/07 00:24:00 UTC
[jira] [Closed] (BCEL-269) Flushing DataOutputStream before calling
toByteArray on the underlying ByteArrayOutputStream
[ https://issues.apache.org/jira/browse/BCEL-269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory closed BCEL-269.
-----------------------------
Resolution: Fixed
Fix Version/s: 6.0
This was fixed by commit {{07e0698ed6961ac535a8971e52d61e53f877f58e}} on {{2016-02-05 01:09:42}} before 6.0 was released.
> 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
> Fix For: 6.0
>
> Attachments: BCEL-269-0.patch
>
>
> 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
(v7.6.3#76005)