harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r765560 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/beancontext/BeanContextSupport.java test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java
Date Thu, 16 Apr 2009 10:26:47 GMT
Author: tellison
Date: Thu Apr 16 10:26:46 2009
New Revision: 765560

URL: http://svn.apache.org/viewvc?rev=765560&view=rev
Log:
Apply patch HARMONY-6143 ([classlib][beans] java.beans.beancontext.BeanContextSupport.readChildren((ObjectInputStream)
null) should throw NullPointerException)

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java?rev=765560&r1=765559&r2=765560&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
Thu Apr 16 10:26:46 2009
@@ -288,10 +288,12 @@
 
             // trigger hook
             synchronized (child) {
+                addSerializable(childBCSC);
                 childJustAddedHook(child, childBCSC);
             }
             if (proxy != null) {
                 synchronized (proxy) {
+                    addSerializable(proxyBCSC);
                     childJustAddedHook(proxy, proxyBCSC);
                 }
             }
@@ -987,10 +989,12 @@
 
             // trigger hook
             synchronized (child) {
+                removeSerializable(childBCSC);
                 childJustRemovedHook(child, childBCSC);
             }
             if (peer != null) {
                 synchronized (peer) {
+                    removeSerializable(peerBCSC);
                     childJustRemovedHook(peer, peerBCSC);
                 }
             }
@@ -1243,19 +1247,6 @@
         serializing = true;
 
         try {
-            // count serializable children
-            synchronized (children) {
-                serializable = 0;
-                for (Iterator iter = children.values().iterator(); iter
-                        .hasNext();) {
-                    BCSChild bcsc = (BCSChild) iter.next();
-                    if (bcsc.child instanceof Serializable
-                            && (bcsc.proxyPeer == null || bcsc.proxyPeer instanceof
Serializable)) {
-                        serializable++;
-                    }
-                }
-            }
-
             oos.defaultWriteObject();
 
             bcsPreSerializationHook(oos);
@@ -1309,6 +1300,29 @@
         }
     }
 
+    /*
+     * Increase variable serializable if child and proxyPeer fields of the given
+     * BCSChild object are serializable
+     */
+    private void addSerializable(BCSChild bcsc) {
+        if (bcsc.child instanceof Serializable
+                && (bcsc.proxyPeer == null || bcsc.proxyPeer instanceof Serializable))
{
+            serializable++;
+        }
+    }
+
+    /*
+     * Decrease variable serializable if child and proxyPeer fields of the given
+     * BCSChild object are serializable
+     */
+    private void removeSerializable(BCSChild bcsc) {
+        if (serializable > 0
+                && bcsc.child instanceof Serializable
+                && (bcsc.proxyPeer == null || bcsc.proxyPeer instanceof Serializable))
{
+            serializable--;
+        }
+    }
+
 }
 
 

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java?rev=765560&r1=765559&r2=765560&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java
Thu Apr 16 10:26:46 2009
@@ -1422,6 +1422,43 @@
         support.records.assertEndOfRecords();
     }
 
+    public void test_readChildren_NPE_scenario1() throws Exception {
+        BeanContextSupport beanContextSupport = new BeanContextSupport();
+        beanContextSupport.add(beanContextSupport);
+        assertEquals(1, beanContextSupport.size());
+        assertFalse(beanContextSupport.isSerializing());
+        try {
+            beanContextSupport.readChildren((ObjectInputStream) null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+    }
+
+    public void test_readChildren_NPE_scenario2() throws Exception {
+        BeanContextSupport beanContextSupport = new BeanContextSupport();
+        beanContextSupport.readChildren((ObjectInputStream) null);
+    }
+
+    public void test_readChildren_NPE_scenario3() throws Exception {
+        BeanContextSupport beanContextSupport = new BeanContextSupport();
+        beanContextSupport.add(new Object());
+        beanContextSupport.readChildren((ObjectInputStream) null);
+    }
+
+    public void test_readChildren_NPE_scenario4() throws Exception {
+        BeanContextSupport beanContextSupport = new BeanContextSupport();
+        beanContextSupport.add("Serializable");
+        try {
+            beanContextSupport.readChildren((ObjectInputStream) null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        beanContextSupport.remove("Serializable");
+        beanContextSupport.readChildren((ObjectInputStream) null);
+    }
+
     public void testRemoveAll() {
         MockBeanContextSupport support = new MockBeanContextSupport();
         support.records.assertRecord("initialize", null);



Mime
View raw message