You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2009/10/01 22:37:33 UTC
svn commit: r820776 -
/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
Author: tellison
Date: Thu Oct 1 20:37:32 2009
New Revision: 820776
URL: http://svn.apache.org/viewvc?rev=820776&view=rev
Log:
Fix unsafe reference to skipBuf (see http://markmail.org/thread/ixknpr4sb63yhvy6)
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java?rev=820776&r1=820775&r2=820776&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java Thu Oct 1 20:37:32 2009
@@ -211,11 +211,16 @@
}
long skipped = 0;
int toRead = n < 4096 ? (int) n : 4096;
- if (skipBuf == null || skipBuf.length < toRead) {
- skipBuf = new byte[toRead];
+ // We are unsynchronized, so take a local copy of the skipBuf at some
+ // point in time.
+ byte[] localBuf = skipBuf;
+ if (localBuf == null || localBuf.length < toRead) {
+ // May be lazily written back to the static. No matter if it
+ // overwrites somebody else's store.
+ skipBuf = localBuf = new byte[toRead];
}
while (skipped < n) {
- int read = read(skipBuf, 0, toRead);
+ int read = read(localBuf, 0, toRead);
if (read == -1) {
return skipped;
}