harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r954547 - in /harmony/enhanced/java/trunk/classlib/modules/beans/src: main/java/java/beans/DefaultPersistenceDelegate.java test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
Date Mon, 14 Jun 2010 16:39:32 GMT
Author: tellison
Date: Mon Jun 14 16:39:31 2010
New Revision: 954547

URL: http://svn.apache.org/viewvc?rev=954547&view=rev
Log:
Apply patch HARMONY-2449 ([classlib][beans] java.beans.DefaultPersistenceDelegate.mutatesTo()
should throw NPE for null parameter)

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

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java?rev=954547&r1=954546&r2=954547&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
Mon Jun 14 16:39:31 2010
@@ -294,25 +294,21 @@ public class DefaultPersistenceDelegate 
      */
     @Override
     protected boolean mutatesTo(Object o1, Object o2) {
-        if (null == o1 || null == o2) {
-            return false;
-        }
-        Class<? extends Object> c = o1.getClass();
         if (this.propertyNames.length > 0) {
+            Class<?> clazz = o1.getClass();
             // Check the "equals" method has been declared
             Method equalMethod = null;
             try {
-                equalMethod = c.getDeclaredMethod("equals", //$NON-NLS-1$
+                equalMethod = clazz.getDeclaredMethod("equals", //$NON-NLS-1$
                         new Class[] { Object.class });
-            } catch (NoSuchMethodException ex) {
-                // ignore
+            } catch (NoSuchMethodException e) {
+                // Ignored
             }
 
             if (null != equalMethod) {
                 return o1.equals(o2);
             }
         }
-
         return super.mutatesTo(o1, o2);
     }
 }
\ No newline at end of file

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java?rev=954547&r1=954546&r2=954547&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
Mon Jun 14 16:39:31 2010
@@ -828,6 +828,45 @@ public class DefaultPersistenceDelegateT
         pd.writeObject(ia, enc);
     }
 
+    class MockDefaultPersistenceDelegate extends DefaultPersistenceDelegate {
+        public MockDefaultPersistenceDelegate(String[] args) {
+            super(args);
+        }
+
+        public boolean mockMutatesTo(Object obj1, Object obj2) {
+            return mutatesTo(obj1, obj2);
+        }
+    }
+
+    public void test_MutatesTo_scenario1() throws Exception {
+        MockDefaultPersistenceDelegate mockDPD = new MockDefaultPersistenceDelegate(
+                new String[1]);
+        try {
+            mockDPD.mockMutatesTo((Object) null, (Object) null);
+            fail("should throw NPE");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            mockDPD.mockMutatesTo((Object) null, (Object) "");
+            fail("should throw NPE");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        assertFalse(mockDPD.mockMutatesTo((Object) "", (Object) null));
+    }
+
+    public void test_MutatesTo_scenario2() throws Exception {
+        MockDefaultPersistenceDelegate mockDPD = new MockDefaultPersistenceDelegate(
+                new String[0]);
+        assertFalse(mockDPD.mockMutatesTo((Object) null, (Object) null));
+        assertFalse(mockDPD.mockMutatesTo((Object) null, (Object) ""));
+        assertFalse(mockDPD.mockMutatesTo((Object) "", (Object) null));
+        assertTrue(mockDPD.mockMutatesTo((Object) "", (Object) ""));
+    }
+
     /*
      * BeanInfo for the MockBean below.
      */



Mime
View raw message