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()];
 buffer = new byte[available];
  final byte[] buffer = new byte[available];
            byte[] input = new byte[dis.available()];
./print/src/test/api/java/common/javax/print/ValueTests.java:562: res = new byte [iStream.available()];
byte[] sfBytes = new byte[signature.available()];
           byte[] data = new
./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.

View raw message