[ https://issues.apache.org/jira/browse/HARMONY-6393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12786062#action_12786062 ] Hudson commented on HARMONY-6393: --------------------------------- Integrated in Harmony-1.5-head-linux-x86_64 #577 (See [http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/577/]) Move readFullyAndClose method into LUNI utils' InputStreamHelper, and roll the input stream exposer code into there too. Replace a number of places that read the full stream with calls to the new helper. Part of (fix "new byte[in.available()]" anti-pattern) > 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.