harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r906860 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/XMLEncoder.java test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
Date Fri, 05 Feb 2010 09:11:23 GMT
Author: zhoukevin
Date: Fri Feb  5 09:11:23 2010
New Revision: 906860

URL: http://svn.apache.org/viewvc?rev=906860&view=rev
Log:
Fix unexpected java.lang.ClassCastException thrown by java.beans.XMLEncoder.checkDeadLoop(Object)
method

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

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java?rev=906860&r1=906859&r2=906860&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLEncoder.java
Fri Feb  5 09:11:23 2010
@@ -836,7 +836,9 @@
                 break;
             }
             
-            if (obj != null && obj.equals(value)) {
+            if (obj != null
+                    && (obj.getClass().isAssignableFrom(value.getClass()))
+                    && obj.equals(value)) {
                 n++;
 
                 if (n >= DEADLOCK_THRESHOLD) {

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?rev=906860&r1=906859&r2=906860&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
Fri Feb  5 09:11:23 2010
@@ -33,6 +33,7 @@
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.StringReader;
+import java.util.Date;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -696,7 +697,7 @@
     /**
      * The test checks that complex scenario store is correct
      */
-    public void testEncodingScenario() {
+    public void testEncodingScenario1() {
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
@@ -721,6 +722,47 @@
         }
     }
 
+    public static class MockClass {
+
+        private Date date = null;
+
+        public MockClass() {
+
+        }
+
+        public MockClass(Date date) {
+            this.date = date;
+        }
+
+        public boolean equals(Object obj) {
+            MockClass mockObj = (MockClass) obj;
+            if (date != null && mockObj.date != null) {
+                return date.equals(mockObj.date);
+            }
+            return false;
+        }
+
+        public Date getDate() {
+            return date;
+        }
+
+        public void setDate(Date date) {
+            this.date = date;
+        }
+    }
+
+    public void testEncodingScenario2() {
+        XMLEncoder xmlEncoder = new XMLEncoder(System.out);
+        xmlEncoder.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() + " is thrown: "
+                        + e.getMessage());
+            }
+        });
+
+        xmlEncoder.writeObject(new MockClass(new Date()));
+    }
+
     /**
      * The test checks that encoder can handle writeExpression in initialize
      */



Mime
View raw message