harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r663433 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/ test/java-internal/java/beans/
Date Thu, 05 Jun 2008 01:52:36 GMT
Author: qiuxx
Date: Wed Jun  4 18:52:36 2008
New Revision: 663433

URL: http://svn.apache.org/viewvc?rev=663433&view=rev
Log:
Apply for HARMONY-4022, ([classlib][beans] Java assertions fail)

Added:
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ProxyPersistenceDelegateTest.java
Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ProxyPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ArrayPersistenceDelegateTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java?rev=663433&r1=663432&r2=663433&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
Wed Jun  4 18:52:36 2008
@@ -71,25 +71,23 @@
 
     @Override
     protected boolean mutatesTo(Object oldInstance, Object newInstance) {
-        assert oldInstance != null && oldInstance.getClass().isArray() : oldInstance;
-
-        if (newInstance != null) {
-            Class<? extends Object> newCl = newInstance.getClass();
-
-            if (!newCl.isArray()) {
-                return false;
-            }
-            // both are arrays
-            int l1 = Array.getLength(oldInstance);
-            int l2 = Array.getLength(newInstance);
-            Class<?> cType1 = oldInstance.getClass().getComponentType();
-            Class<?> cType2 = newCl.getComponentType();
-
-            if (l1 == l2 && cType1.equals(cType2)) {
-                return true;
-            }
+        if(null == oldInstance || null == newInstance){
             return false;
         }
+        
+        if(!oldInstance.getClass().isArray() || !newInstance.getClass().isArray()){
+            return false;
+        }
+        
+        // both are array
+        int l1 = Array.getLength(oldInstance);
+        int l2 = Array.getLength(newInstance);
+        Class<?> cType1 = oldInstance.getClass().getComponentType();
+        Class<?> cType2 = newInstance.getClass().getComponentType();
+        if(l1 == l2 && cType1.equals(cType2)){
+            return true;
+        }
+        
         return false;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ProxyPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ProxyPersistenceDelegate.java?rev=663433&r1=663432&r2=663433&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ProxyPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ProxyPersistenceDelegate.java
Wed Jun  4 18:52:36 2008
@@ -35,14 +35,15 @@
         // check for consistency
         assert oldInstance instanceof Proxy : oldInstance;
         assert newInstance instanceof Proxy : newInstance;
-        assert newInstance == oldInstance;
         super.initialize(type, oldInstance, newInstance, out);
     }
 
     @Override
     protected boolean mutatesTo(Object oldInstance, Object newInstance) {
-        assert oldInstance instanceof Proxy : oldInstance;
-        assert oldInstance == newInstance;
-        return super.mutatesTo(oldInstance, newInstance);
+        if((oldInstance instanceof Proxy) && (newInstance instanceof Proxy)){
+            return super.mutatesTo(oldInstance, newInstance);
+        }
+        
+        return false;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java?rev=663433&r1=663432&r2=663433&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
Wed Jun  4 18:52:36 2008
@@ -95,7 +95,6 @@
 
     StandardBeanInfo(Class<?> beanClass, BeanInfo explicitBeanInfo, Class<?>
stopClass)
             throws IntrospectionException {
-        assert (beanClass != null);
         this.beanClass = beanClass;
         /*--------------------------------------------------------------------------------------
          * There are 3 aspects of BeanInfo that must be supplied:

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ArrayPersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ArrayPersistenceDelegateTest.java?rev=663433&r1=663432&r2=663433&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ArrayPersistenceDelegateTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ArrayPersistenceDelegateTest.java
Wed Jun  4 18:52:36 2008
@@ -37,13 +37,90 @@
         pd = new ArrayPersistenceDelegate();
     }
 
+    @Override
+    protected void tearDown() throws Exception {
+        pd = null;
+        super.tearDown();
+    }
+    
     public void testMutates() {
         assertFalse(pd.mutatesTo(new int[] { 1 }, null));
         assertFalse(pd.mutatesTo(null, null));
         assertFalse(pd.mutatesTo(new int[1], new int[2]));
         assertTrue(pd.mutatesTo(new int[] { 1, 3 }, new int[] { 1, 2 }));
     }
-
+    
+    /*
+     * test mutates with wrapper array
+     */
+    public void test_MutatesTo_WrapperArray() {
+        // Regression for Harmony-4022
+        // one wrapper array and null
+        assertFalse(pd.mutatesTo(new Integer[] { 1, 2, 3 }, null));
+        assertFalse(pd.mutatesTo(new Boolean[] { true, false }, null));
+        assertFalse(pd.mutatesTo(new Short[] { 1, 2 }, null));
+        assertFalse(pd.mutatesTo(new Long[] { 23000000094382l, 23000000094383l }, null));
+        assertFalse(pd.mutatesTo(new Character[] { 'a', 'b', 'c'}, null));
+        assertFalse(pd.mutatesTo(new Float[] { 0.1f, 0.2f }, null));
+        assertFalse(pd.mutatesTo(new Double[] { 0.1, 0.2 }, null));
+        
+        // two wrapper arries with the same component type but different length
+        assertFalse(pd.mutatesTo(new Integer[] { 1, 2, 3 }, new Integer[] { 1, 2}));
+        assertFalse(pd.mutatesTo(new Boolean[] { true, false }, new Boolean[] { true }));
+        assertFalse(pd.mutatesTo(new Short[] { 1, 2 }, new Short[] { 1, 2, 3}));
+        assertFalse(pd.mutatesTo(new Long[] { 23000000094382l, 23000000094383l }, new Long[]
{ 23000000094382l}));
+        assertFalse(pd.mutatesTo(new Character[] { 'a', 'b', 'c'}, new Character[] {}));
+        assertFalse(pd.mutatesTo(new Float[] { 0.1f, 0.2f }, new Float[] { 0.1f, 0.2f, 0.3f}));
+        assertFalse(pd.mutatesTo(new Double[] { 0.1, 0.2 }, new Double[] { 0.1 }));
+        
+        // two wrapper arries with the same length but different component types
+        assertFalse(pd.mutatesTo(new Integer[] { 1, 2, 3 }, new Boolean[] { true, false }));
+        assertFalse(pd.mutatesTo(new Boolean[] { true, false }, new Short[] { 1, 2 }));
+        assertFalse(pd.mutatesTo(new Short[] { 1, 2 }, new Long[] { 23000000094382l, 23000000094383l
}));
+        assertFalse(pd.mutatesTo(new Long[] { 23000000094382l, 23000000094383l }, new Character[]
{ 'a', 'b', 'c'}));
+        assertFalse(pd.mutatesTo(new Character[] { 'a', 'b', 'c'}, new Float[] { 0.1f, 0.2f
}));
+        assertFalse(pd.mutatesTo(new Float[] { 0.1f, 0.2f }, new Double[] { 0.1 }));
+        
+        // two wrapper arries with the same length and component type but different internal
values
+        assertTrue(pd.mutatesTo(new Integer[] { 1, 2, 3 }, new Integer[] { 5, 6, 7 }));
+        assertTrue(pd.mutatesTo(new Boolean[] { true, false, false}, new Boolean[] { false,
true, true}));
+        assertTrue(pd.mutatesTo(new Short[] { 1, 2 }, new Short[] { 4, 5 }));
+        assertTrue(pd.mutatesTo(new Long[] { 23000000094382l, 23000000094383l }, new Long[]
{ 534300002l, 23020094383l }));
+        assertTrue(pd.mutatesTo(new Character[] { 'a', 'b', 'c'}, new Character[] { 'd',
'e', 'f'}));
+        assertTrue(pd.mutatesTo(new Float[] { 0.1f, 0.2f }, new Float[] { 0.4f, 0.6f }));
+        assertTrue(pd.mutatesTo(new Double[] { 0.1, 0.2 }, new Double[] { 0.3, 0.343 }));
+    }
+    
+    /*
+     * test mutatesTo with object array
+     */
+    public void test_MutatesTo_ObjectArray(){
+        // Regression for Harmony-4022
+        // one object array and null
+        assertFalse(pd.mutatesTo(new MockAObject[] { new MockAObject() }, null));
+        assertFalse(pd.mutatesTo(new MockBObject[] { new MockBObject() }, null));
+        assertFalse(pd.mutatesTo(new MockObject[] { new MockAObject(), new MockBObject()},
null));
+        
+        // two wrapper arries with the same component type but different length
+        assertFalse(pd.mutatesTo(new MockObject[1], new MockObject[2]));
+        assertFalse(pd.mutatesTo(new MockAObject[1], new MockAObject[2]));
+        assertFalse(pd.mutatesTo(new MockBObject[1], new MockBObject[2]));
+        
+        // two object array with the same length but different component types
+        assertFalse(pd.mutatesTo(new MockAObject[] { new MockAObject() }, new MockBObject[]
{ new MockBObject() }));
+        assertFalse(pd.mutatesTo(new MockObject[] {new MockObject()}, new MockAObject[] {
new MockAObject() }));
+        assertFalse(pd.mutatesTo(new MockObject[] {new MockAObject()}, new MockAObject[]
{ new MockAObject() }));
+        assertFalse(pd.mutatesTo(new MockObject[] {new MockBObject()}, new MockAObject[]
{ new MockAObject() }));
+        assertFalse(pd.mutatesTo(new MockObject[] {new MockObject()}, new MockBObject[] {
new MockBObject() }));
+        assertFalse(pd.mutatesTo(new MockObject[] {new MockBObject()}, new MockBObject[]
{ new MockBObject() }));
+        assertFalse(pd.mutatesTo(new MockObject[] {new MockAObject()}, new MockBObject[]
{ new MockBObject() }));
+        
+        // two object array with the same length and component type but differnt internal
values
+        assertTrue(pd.mutatesTo(new MockObject[] { new MockAObject() }, new MockObject[]
{ new MockBObject() }));
+        assertTrue(pd.mutatesTo(new MockAObject[] { new MockAObject(1) }, new MockAObject[]
{ new MockAObject(2) }));
+        assertTrue(pd.mutatesTo(new MockBObject[] { new MockBObject(1) }, new MockBObject[]
{ new MockBObject(2) }));
+    }
+    
     public void testInitialize() {
         // TBD
     }
@@ -58,5 +135,35 @@
         assertSame(Integer.TYPE, exp.getArguments()[0]);
         assertEquals(new Integer(3), exp.getArguments()[1]);
     }
+    
+    public class MockObject {
+        
+    }
+    
+    public class MockAObject extends MockObject {
+        String name = "A Object";
+        int id = 0x01;
+        
+        public MockAObject() {
+            
+        }
+        
+        public MockAObject(int idValue){
+            id = idValue;
+        }
+    }
+    
+    public class MockBObject extends MockObject {
+        String name = "B Object";
+        int id = 0x02;
+        
+        public MockBObject(){
+            
+        }
+        
+        public MockBObject(int idValue){
+            id = idValue;
+        }
+    }
 
 }

Added: harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ProxyPersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ProxyPersistenceDelegateTest.java?rev=663433&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ProxyPersistenceDelegateTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java-internal/java/beans/ProxyPersistenceDelegateTest.java
Wed Jun  4 18:52:36 2008
@@ -0,0 +1,98 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import junit.framework.TestCase;
+
+public class ProxyPersistenceDelegateTest extends TestCase {
+
+    private ProxyPersistenceDelegate pd = null;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        pd = new ProxyPersistenceDelegate();
+    }
+
+    protected void tearDown() throws Exception {
+        pd = null;
+        super.tearDown();
+    }
+
+    /*
+     * test mutatesTo method
+     */
+    public void test_MutatesTo() {
+        // Regression for Harmony-4022
+        Object proxy1 = Proxy.newProxyInstance(
+                this.getClass().getClassLoader(), new Class[] {
+                        ITestReturnObject.class, ITestReturnString.class },
+                new TestProxyHandler(new TestProxyImpl()));
+        Object proxy2 = Proxy.newProxyInstance(
+                this.getClass().getClassLoader(),
+                new Class[] { ITestReturnObject.class }, new TestProxyHandler(
+                        new TestProxyImpl()));
+
+        assertFalse(pd.mutatesTo(null, null));
+        assertFalse(pd.mutatesTo(new MockAObject(), new MockAObject()));
+        assertFalse(pd.mutatesTo(new MockAObject(), new MockBObject()));
+        assertFalse(pd.mutatesTo(proxy1, null));
+        assertFalse(pd.mutatesTo(proxy1, proxy2));
+        assertTrue(pd.mutatesTo(proxy1, proxy1));
+    }
+
+    public class MockAObject {
+
+    }
+
+    public class MockBObject {
+
+    }
+
+    public static interface ITestReturnObject {
+        Object f();
+    }
+
+    public static interface ITestReturnString {
+        String f();
+    }
+
+    public static class TestProxyImpl implements ITestReturnObject,
+            ITestReturnString {
+        public String f() {
+            return null;
+        }
+    }
+
+    public static class TestProxyHandler implements InvocationHandler {
+        private Object proxied;
+
+        public TestProxyHandler(Object object) {
+            proxied = object;
+        }
+
+        public Object invoke(Object object, Method method, Object[] args)
+                throws Throwable {
+            return method.invoke(proxied, args);
+        }
+    }
+
+}



Mime
View raw message