You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2008/06/12 12:08:50 UTC

svn commit: r667023 - 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

Author: qiuxx
Date: Thu Jun 12 03:08:49 2008
New Revision: 667023

URL: http://svn.apache.org/viewvc?rev=667023&view=rev
Log:
Apply for HARMONY-5866, ([classlib][beans] java.beans.XMLDecoder(4) always use Thread.currentThread().getContextClassLoader())

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=667023&r1=667022&r2=667023&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 Thu Jun 12 03:08:49 2008
@@ -536,7 +536,7 @@
      *            an input stream of xml
      */
     public XMLDecoder(InputStream inputStream) {
-        this(inputStream, null, null);
+        this(inputStream, null, null, null);
     }
 
     /**
@@ -548,7 +548,7 @@
      *            the owner of this decoder
      */
     public XMLDecoder(InputStream inputStream, Object owner) {
-        this(inputStream, owner, null);
+        this(inputStream, owner, null, null);
     }
 
     /**
@@ -563,6 +563,11 @@
      */
     public XMLDecoder(InputStream inputStream, Object owner,
             ExceptionListener listener) {
+        this(inputStream, owner, listener, null);
+    }
+
+    public XMLDecoder(InputStream inputStream, Object owner,
+            ExceptionListener listener, ClassLoader cl) {
         if (inputStream == null) {
             throw new IllegalArgumentException("Input stream cannot be null"); //$NON-NLS-1$
         }
@@ -570,7 +575,8 @@
         this.owner = owner;
         this.listener = (listener == null) ? new DefaultExceptionListener()
                 : listener;
-
+        defaultClassLoader = cl;
+        
         try {
             SAXParserFactory.newInstance().newSAXParser().parse(inputStream,
                     new SAXHandler());
@@ -579,12 +585,6 @@
         }
     }
 
-    public XMLDecoder(InputStream inputStream, Object owner,
-            ExceptionListener listener, ClassLoader cl) {
-        this(inputStream, owner, listener);
-        defaultClassLoader = cl;
-    }
-
     /**
      * Close the input stream of xml data.
      */

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=667023&r1=667022&r2=667023&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 Thu Jun 12 03:08:49 2008
@@ -74,6 +74,58 @@
         }
 
     }
+    
+    /*
+     * test XMLDecoder constructor with null inputStream argument
+     */
+    public void test_Constructor_NullInputStream() {
+        XMLDecoder xmlDecoder;
+        try {
+            xmlDecoder = new XMLDecoder(null);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException iae) {
+            // Expected
+        }
+        
+        try{
+            xmlDecoder = new XMLDecoder(null, null);
+        }catch(IllegalArgumentException iae){
+            // Expected
+        }
+        
+        try{
+            xmlDecoder = new XMLDecoder(null, null, null);
+        }catch(IllegalArgumentException iae){
+            // Expected
+        }
+        
+        try{
+            xmlDecoder = new XMLDecoder(null, null, null, null);
+        }catch(IllegalArgumentException iae){
+            // Expected
+        }
+        
+    }
+    
+    /*
+     * test XMLDecoder constructor
+     */
+    public void test_Constructor_Normal() throws Exception {
+        XMLDecoder xmlDecoder;
+        xmlDecoder = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+        assertEquals(null, xmlDecoder.getOwner());
+        
+        final Vector<Exception> exceptions = new Vector<Exception>();
+        ExceptionListener el = new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                exceptions.addElement(e);
+            }
+        };
+        
+        xmlDecoder = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this, el);
+        assertEquals(el, xmlDecoder.getExceptionListener());
+        assertEquals(this, xmlDecoder.getOwner());
+    }
 
     public void testConstructor_ClassLoader() {
         XMLDecoder dec;