harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-6393) fix "new byte[in.available()]" anti-pattern
Date Fri, 04 Dec 2009 19:21:20 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-6393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12786089#action_12786089
] 

Tim Ellison commented on HARMONY-6393:
--------------------------------------

These have been fixed:

./rmi/src/main/java/java/rmi/server/RMIClassLoader.java:214: byte[] buf = new byte[in.available()];
./luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java:670:
byte[] input = new byte[dis.available()];
./security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java:147: byte[]
sfBytes = new byte[signature.available()];


These are not to be fixed:

./luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java:86: buffer = new
byte[available];
./luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java:52: final
byte[] buffer = new byte[available];
(rolled into the helper, they are looking at the known good available inst var)


These still need looking at:

./print/src/test/api/java/common/javax/print/ValueTests.java:562: res = new byte [iStream.available()];
(will the process stdout stream return an EOF marker?)

./swing/src/main/java/common/javax/swing/plaf/basic/BasicLookAndFeel.java:1022: byte[] data
= new
byte[audioStream.available()];
(this is commented out code, consider enabling it first?)

./swing/src/main/java/common/javax/swing/text/html/parser/DTD.java:145: byte[] enc = new byte[stream.available()];
(this is public API, see if it should close stream or not? if not can't use helper as-is)

> fix "new byte[in.available()]" anti-pattern
> -------------------------------------------
>
>                 Key: HARMONY-6393
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6393
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Elliott Hughes
>
> there are a number of places where it's assumed that you can read a file in its entirety
by allocating a byte[] corresponding to the size reported by InputStream.available. using
a ByteArrayOutputStream and reading until EOF (rather than any assumed length) is the best
choice (because it works for files where stat(2) doesn't report the size correctly, such as
in Linux's /proc), but even File.length would be good enough.
> here are all the matches for "new byte.*available". this may miss cases ("int len = in.available();
... new byte[len]", say), but it doesn't appear to contain any false positives.
> ./rmi/src/main/java/java/rmi/server/RMIClassLoader.java:214: byte[] buf = new byte[in.available()];
> ./luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java:86:       
      buffer = new byte[available];
> ./luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java:52:
     final byte[] buffer = new byte[available];
> ./luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java:670:
            byte[] input = new byte[dis.available()];
> ./print/src/test/api/java/common/javax/print/ValueTests.java:562: res = new byte [iStream.available()];
> ./security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java:147:
     byte[] sfBytes = new byte[signature.available()];
> ./swing/src/main/java/common/javax/swing/plaf/basic/BasicLookAndFeel.java:1022:     
                byte[] data = new
> byte[audioStream.available()];
> ./swing/src/main/java/common/javax/swing/text/html/parser/DTD.java:145:      byte[] enc
= new byte[stream.available()];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message