harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r597490 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/StringReader.java test/api/common/tests/api/java/io/StringReaderTest.java
Date Thu, 22 Nov 2007 21:11:12 GMT
Author: tellison
Date: Thu Nov 22 13:11:11 2007
New Revision: 597490

URL: http://svn.apache.org/viewvc?rev=597490&view=rev
Log:
Partial fix for HARMONY-5077 ([classlib][io] a stress test org.apache.harmony.test.stress.api.java.io.stress.readers.StringReader.StringReaderWriterStressTest.testManyStreams
deadlocks).
Testing shows that the string in a StringReader is not considered the lock object, and the
lock object is not used in close().

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringReader.java?rev=597490&r1=597489&r2=597490&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringReader.java Thu
Nov 22 13:11:11 2007
@@ -42,7 +42,7 @@
      *            the String to filter reads on.
      */
     public StringReader(String str) {
-        super(str);
+        super();
         this.str = str;
         this.count = str.length();
     }
@@ -54,12 +54,7 @@
      */
     @Override
     public void close() {
-        synchronized (lock) {
-            if (isClosed()) {
-                return;
-            }
-            str = null;
-        }
+        str = null;
     }
 
     /**
@@ -139,14 +134,17 @@
      */
     @Override
     public int read(char buf[], int offset, int len) throws IOException {
-        // avoid int overflow
-        if (offset < 0 || offset > buf.length || len < 0
-                || len > buf.length - offset) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
         synchronized (lock) {
             if (isClosed()) {
                 throw new IOException(Msg.getString("K0083")); //$NON-NLS-1$
+            }
+            // avoid int overflow
+            if (offset < 0 || offset > buf.length || len < 0
+                    || len > buf.length - offset) {
+                throw new ArrayIndexOutOfBoundsException();
+            }
+            if (len == 0) {
+                return 0;
             }
             if (pos == this.count) {
                 return -1;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java?rev=597490&r1=597489&r2=597490&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/StringReaderTest.java
Thu Nov 22 13:11:11 2007
@@ -147,22 +147,24 @@
                                 .equals(testString.substring(5, 7)));
 	}
 
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
+	// Regression test for HARMONY-5077
+    static boolean finish = false;
 
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
+    public void test_synchronization() {
+        String anything = "Hello world";
+        final StringReader sr = new StringReader(anything);
+        Thread other = new Thread(new Runnable() {
+            public void run() {
+                sr.close();
+                finish = true;
+            };
+        });
 
-		try {
-			sr.close();
-		} catch (Exception e) {
-		}
-	}
+        synchronized (anything) {
+            other.start();
+            while (!finish) {
+                Thread.yield();
+            }
+        }
+    }
 }



Mime
View raw message