harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jessewil...@apache.org
Subject svn commit: r835012 - in /harmony/enhanced/classlib/trunk: modules/luni/make/ modules/luni/src/main/java/java/io/ modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ support/src/test/java/org/apache/harmony/testframework/
Date Wed, 11 Nov 2009 18:57:11 GMT
Author: jessewilson
Date: Wed Nov 11 18:57:11 2009
New Revision: 835012

URL: http://svn.apache.org/viewvc?rev=835012&view=rev
Log:
Fixing FilterOutputStream to no longer swallow exceptions thrown by the underlying stream.

Also fixing the test case - in the first round I'd missed the fact that PrintWriter doesn't
throw exceptions in its API, so the WrapperTester needed to be adjusted to support that. 

Also removing the now-passing tests from the excludes list.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamTesterTest.java
    harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/WrapperTester.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common?rev=835012&r1=835011&r2=835012&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common Wed Nov 11 18:57:11 2009
@@ -1,2 +1 @@
 org/apache/harmony/luni/tests/java/net/ExcludedProxyTest.java
-org/apache/harmony/luni/tests/java/io/OutputStreamTesterTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java?rev=835012&r1=835011&r2=835012&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java
Wed Nov 11 18:57:11 2009
@@ -55,13 +55,28 @@
      */
     @Override
     public void close() throws IOException {
+        Exception thrown = null;
         try {
             flush();
-        } catch (IOException e) {
-            // Ignored
+        } catch (Exception e) {
+            thrown = e;
+        }
+
+        try {
+            out.close();
+        } catch (Exception e) {
+            if (thrown != null) {
+                thrown = e;
+            }
+        }
+
+        if (thrown != null) {
+            if (thrown instanceof IOException) {
+                throw (IOException) thrown;
+            } else {
+                throw (RuntimeException) thrown;
+            }
         }
-        /* Make sure we clean up this stream if exception fires */
-        out.close();
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamTesterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamTesterTest.java?rev=835012&r1=835011&r2=835012&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamTesterTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamTesterTest.java
Wed Nov 11 18:57:11 2009
@@ -65,7 +65,7 @@
         suite.addTest(new FilterOutputStreamTester().createTests());
         suite.addTest(new DataOutputStreamTester().createTests());
         suite.addTest(new ObjectOutputStreamTester().createTests());
-        suite.addTest(new PrintStreamTester().createTests());
+        suite.addTest(new PrintStreamTester().setExceptionSuppressed(true).createTests());
 
         return suite;
     }

Modified: harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/WrapperTester.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/WrapperTester.java?rev=835012&r1=835011&r2=835012&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/WrapperTester.java
(original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/WrapperTester.java
Wed Nov 11 18:57:11 2009
@@ -30,6 +30,8 @@
  */
 public abstract class WrapperTester {
 
+    private boolean exceptionsSuppressed;
+
     /**
      * Creates a new output stream that receives one stream of bytes, optionally
      * transforms it, and emits another stream of bytes to {@code delegate}.
@@ -42,11 +44,28 @@
      */
     public abstract byte[] decode(byte[] delegateBytes) throws Exception;
 
+    /**
+     * Configures whether the wrapper is expected to suppress exceptions thrown
+     * by the underlying stream. This is the case for wrappers like {@code
+     * PrintWriter}, that reports errors using an API method.
+     */
+    public WrapperTester setExceptionSuppressed(boolean suppressExceptions) {
+        this.exceptionsSuppressed = suppressExceptions;
+        return this;
+    }
+
     public final TestSuite createTests() {
         TestSuite result = new TestSuite();
         result.addTest(new WrapperSinkTester().createTests());
-        result.addTest(new WrapperTestCase("wrapperTestFlushThrowsViaFlush"));
-        result.addTest(new WrapperTestCase("wrapperTestFlushThrowsViaClose"));
+
+        if (exceptionsSuppressed) {
+            result.addTest(new WrapperTestCase("wrapperTestFlushThrowsViaFlushSuppressed"));
+            result.addTest(new WrapperTestCase("wrapperTestFlushThrowsViaCloseSuppressed"));
+        } else {
+            result.addTest(new WrapperTestCase("wrapperTestFlushThrowsViaFlush"));
+            result.addTest(new WrapperTestCase("wrapperTestFlushThrowsViaClose"));
+        }
+
         return result;
     }
 
@@ -77,6 +96,24 @@
             super(name);
         }
 
+        public void wrapperTestFlushThrowsViaFlushSuppressed() throws Exception {
+            FailOnFlushOutputStream delegate = new FailOnFlushOutputStream();
+            OutputStream o = create(delegate);
+            o.write(new byte[] { 8, 6, 7, 5 });
+            o.write(new byte[] { 3, 0, 9 });
+            o.flush();
+            assertTrue(delegate.flushed);
+        }
+
+        public void wrapperTestFlushThrowsViaCloseSuppressed() throws Exception {
+            FailOnFlushOutputStream delegate = new FailOnFlushOutputStream();
+            OutputStream o = create(delegate);
+            o.write(new byte[] { 8, 6, 7, 5 });
+            o.write(new byte[] { 3, 0, 9 });
+            o.close();
+            assertTrue(delegate.flushed);
+        }
+
         public void wrapperTestFlushThrowsViaFlush() throws Exception {
             FailOnFlushOutputStream delegate = new FailOnFlushOutputStream();
 



Mime
View raw message