harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r582746 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/org/apache/harmony/beans/editors/ColorEditor.java test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
Date Mon, 08 Oct 2007 08:41:17 GMT
Author: tonywu
Date: Mon Oct  8 01:41:14 2007
New Revision: 582746

URL: http://svn.apache.org/viewvc?rev=582746&view=rev
Log:
Apply patch Harmony-4852 with minor modification ([classlib][beans] ColorEditor.getAsText()
throws NPE when color is null)

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java?rev=582746&r1=582745&r2=582746&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
Mon Oct  8 01:41:14 2007
@@ -32,14 +32,14 @@
 @SuppressWarnings("serial")
 public class ColorEditor extends Panel implements PropertyEditor {
 
-List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
-    
+    List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
+
     private Color value;
-    
+
     private Object source;
-    
+
     public ColorEditor(Object source) {
-        if(null == source) {
+        if (null == source) {
             throw new NullPointerException();
         }
         this.source = source;
@@ -74,23 +74,27 @@
     }
 
     public void setValue(Object value) {
-        if( null == value) {
+        if (null == value) {
             return;
         }
         Object oldValue = this.value;
         this.value = (Color) value;
         PropertyChangeEvent changeAllEvent = new PropertyChangeEvent(this,
                 "value", oldValue, value); //$NON-NLS-1$
-        PropertyChangeListener[] copy = new PropertyChangeListener[listeners.size()];
+        PropertyChangeListener[] copy = new PropertyChangeListener[listeners
+                .size()];
         listeners.toArray(copy);
         for (PropertyChangeListener listener : copy) {
             listener.propertyChange(changeAllEvent);
         }
     }
-    
+
     @SuppressWarnings("nls")
-    public String getAsText(){
-        Color c = (Color)getValue();
+    public String getAsText() {
+        Color c = (Color) getValue();
+        if (null == c) {
+            return "null";
+        }
         StringBuilder sb = new StringBuilder(14);
         sb.append(c.getRed());
         sb.append(",");
@@ -99,7 +103,7 @@
         sb.append(c.getBlue());
         return sb.toString();
     }
-    
+
     @SuppressWarnings("nls")
     public void setAsText(String text) {
         if (null == text) {
@@ -123,7 +127,6 @@
             throw new IllegalArgumentException(aText);
         }
     }
-    
 
     public boolean isPaintable() {
         return true;
@@ -140,7 +143,7 @@
     public Object getValue() {
         return value;
     }
-    
+
     @Override
     public synchronized void removePropertyChangeListener(
             PropertyChangeListener listener) {
@@ -154,7 +157,7 @@
             PropertyChangeListener listener) {
         listeners.add(listener);
     }
-    
+
     public void firePropertyChange() {
         if (listeners.isEmpty()) {
             return;

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java?rev=582746&r1=582745&r2=582746&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
Mon Oct  8 01:41:14 2007
@@ -772,6 +772,8 @@
     }
     public void testColorEditor() throws Exception{
         PropertyEditor e2 = PropertyEditorManager.findEditor(Color.class);
+        assertNull(e2.getValue());
+        assertEquals("null", e2.getAsText());
         e2.setValue(Color.RED);
         e2.setAsText(e2.getAsText());
         assertNull(e2.getTags());



Mime
View raw message