harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r728607 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/XMLDecoder.java test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
Date Mon, 22 Dec 2008 04:47:27 GMT
Author: qiuxx
Date: Sun Dec 21 20:47:27 2008
New Revision: 728607

URL: http://svn.apache.org/viewvc?rev=728607&view=rev
Log:
Apply for HARMONY-6015,([classlib] [beans] Exceptions should be thrown and handled in XMLDecoder.readObject()
rather than XMLDecoder's constructors)

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java?rev=728607&r1=728606&r2=728607&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
Sun Dec 21 20:47:27 2008
@@ -576,13 +576,6 @@
         this.listener = (listener == null) ? new DefaultExceptionListener()
                 : listener;
         defaultClassLoader = cl;
-        
-        try {
-            SAXParserFactory.newInstance().newSAXParser().parse(inputStream,
-                    new SAXHandler());
-        } catch (Exception e) {
-            this.listener.exceptionThrown(e);
-        }
     }
 
     /**
@@ -623,6 +616,13 @@
      */
     @SuppressWarnings("nls")
     public Object readObject() {
+        try {
+            SAXParserFactory.newInstance().newSAXParser().parse(inputStream,
+                    new SAXHandler());
+        } catch (Exception e) {
+            this.listener.exceptionThrown(e);
+        }
+        
         if (readObjIndex >= readObjs.size()) {
             throw new ArrayIndexOutOfBoundsException("no more objects to read");
         }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java?rev=728607&r1=728606&r2=728607&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
Sun Dec 21 20:47:27 2008
@@ -430,6 +430,31 @@
         assertEquals(o2, t2.getV());
     }
 
+    public void testSetExceptionListener_Called() throws Exception {
+        class MockExceptionListener implements ExceptionListener {
+
+            private boolean isCalled = false;
+
+            public void exceptionThrown(Exception e) {
+                isCalled = true;
+            }
+
+            public boolean isCalled() {
+                return isCalled;
+            }
+        }
+        
+        XMLDecoder xmlDecoder = new XMLDecoder(new ByteArrayInputStream(
+                "<java><string/>".getBytes("UTF-8")));
+        MockExceptionListener mockListener = new MockExceptionListener();
+        xmlDecoder.setExceptionListener(mockListener);
+        
+        assertFalse(mockListener.isCalled());        
+        // Real Parsing should occur in method of ReadObject rather constructor.
+        assertNotNull(xmlDecoder.readObject());
+        assertTrue(mockListener.isCalled());
+    }
+
     public void testSetExceptionListener() {
         XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
         Object defaultL = dec.getExceptionListener();



Mime
View raw message