harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r554857 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/PropertyEditorSupport.java test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorSupportTest.java
Date Tue, 10 Jul 2007 07:12:08 GMT
Author: pyang
Date: Tue Jul 10 00:12:07 2007
New Revision: 554857

URL: http://svn.apache.org/viewvc?view=rev&rev=554857
Log:
Fix 2 bugs in PropertyEditorSupport: 1. setSource(null) should not throw NPE(the original
tests fail on RI, also updated accordingly), 2. firePropertyChange should fire an event with
the source only

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

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorSupport.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorSupport.java?view=diff&rev=554857&r1=554856&r2=554857
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorSupport.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorSupport.java
Tue Jul 10 00:12:07 2007
@@ -79,10 +79,7 @@
         return newValue;
     }
 
-    public void setSource(Object source) {
-        if (source == null) {
-            throw new NullPointerException(Messages.getString("beans.0C")); //$NON-NLS-1$
-        }
+    public void setSource(Object source) {        
         this.source = source;
     }
 
@@ -115,15 +112,22 @@
     }
 
     public void firePropertyChange() {
-        if (listeners.size() > 0) {
-            PropertyChangeEvent event = new PropertyChangeEvent(source, null,
-                    oldValue, newValue);
-            Iterator<PropertyChangeListener> iterator = listeners.iterator();
-
-            while (iterator.hasNext()) {
-                PropertyChangeListener listener = iterator.next();
-                listener.propertyChange(event);
-            }
+        if (listeners.isEmpty()) {
+            return;
+        }
+
+        List<PropertyChangeListener> copy = new ArrayList<PropertyChangeListener>(
+                listeners.size());
+        synchronized (listeners) {
+            copy.addAll(listeners);
+        }
+
+        PropertyChangeEvent changeAllEvent = new PropertyChangeEvent(source,
+                null, null, null);
+        for (Iterator<PropertyChangeListener> listenersItr = copy.iterator(); listenersItr
+                .hasNext();) {
+            PropertyChangeListener listna = listenersItr.next();
+            listna.propertyChange(changeAllEvent);
         }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorSupportTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorSupportTest.java?view=diff&rev=554857&r1=554856&r2=554857
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorSupportTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorSupportTest.java
Tue Jul 10 00:12:07 2007
@@ -287,11 +287,24 @@
         support.setSource(source);
         assertSame(source, support.getSource());
 
-        try {
-            support.setSource(null);
-            fail("No expected NullPointerException");
-        } catch (NullPointerException e) {
-        }
+        support.setSource(null);
+    }
+    
+    public void testSetValue_Event() {
+        PropertyEditorSupport support = new PropertyEditorSupport();
+        Object source = new Object();
+        support.setSource(source);
+        MockPropertyChangeListener listener = new MockPropertyChangeListener();
+        support.addPropertyChangeListener(listener);
+        
+        support.setValue(new Object());        
+        PropertyChangeEvent event = listener.getEvent();
+        assertNotNull(event);
+        assertEquals(source, event.getSource());
+        assertNull(event.getNewValue());
+        assertNull(event.getOldValue());
+        assertNull(event.getPropagationId());
+        assertNull(event.getPropertyName());        
     }
 
     public static class MockSource {
@@ -411,5 +424,21 @@
                             : this.eventSource.equals(other.eventSource)) && (this.label
== null ? other.label == null
                     : this.label.equals(other.label)));
         }
+    }
+    
+    public class MockPropertyChangeListener implements PropertyChangeListener
+    {
+
+        private PropertyChangeEvent event;        
+        public void propertyChange(PropertyChangeEvent event) {
+            
+            this.event = event;
+        }
+        
+        public PropertyChangeEvent getEvent()
+        {
+            return event;
+        }
+        
     }
 }



Mime
View raw message