harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Elliott Hughes (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-6393) fix "new byte[in.available()]" anti-pattern
Date Fri, 27 Nov 2009 16:48:20 GMT
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