harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r396796 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/PropertyEditorManager.java test/java/tests/api/java/beans/PropertyEditorManagerTest.java
Date Tue, 25 Apr 2006 07:14:34 GMT
Author: mloenko
Date: Tue Apr 25 00:14:33 2006
New Revision: 396796

URL: http://svn.apache.org/viewcvs?rev=396796&view=rev
Log:
fixes for HARMONY-258
java.beans.PropertyEditorManager.findEditor/registerEditor should throw NullPointerExceptions

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorManager.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorManager.java?rev=396796&r1=396795&r2=396796&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyEditorManager.java
Tue Apr 25 00:14:33 2006
@@ -41,16 +41,18 @@
      * @com.intel.drl.spec_ref
      */
     public static void registerEditor(Class targetType, Class editorClass) {
-        if (targetType != null) {
-            SecurityManager sm = System.getSecurityManager();
-            if (sm != null) {
-                sm.checkPropertiesAccess();
-            }
-            if (editorClass != null) {
-                registeredEditors.put(targetType, editorClass);
-            } else {
-                registeredEditors.remove(targetType);
-            }
+        if (targetType == null) {
+            throw new NullPointerException();
+        }
+
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPropertiesAccess();
+        }
+        if (editorClass != null) {
+            registeredEditors.put(targetType, editorClass);
+        } else {
+            registeredEditors.remove(targetType);
         }
     }
 
@@ -58,55 +60,54 @@
      * @com.intel.drl.spec_ref
      */
     public static synchronized PropertyEditor findEditor(Class targetType) {
+        if (targetType == null) {
+            throw new NullPointerException();
+        }
+
         Class editorClass = null;
         PropertyEditor editor = null;
-        
-        if (targetType != null) {
-            editorClass = (Class) registeredEditors.get(targetType);
-            
-            if (editorClass == null) {
-                String editorClassName = targetType.getName() + "Editor";
-                ClassLoader loader = targetType.getClassLoader();
-
-				if (loader == null) {
-					loader = Thread.currentThread().getContextClassLoader();
-				}
-
-				try {
-					editorClass = Class.forName(editorClassName, true, loader);
-                } catch (ClassNotFoundException cnfe) {
-                    String shortEditorClassName = editorClassName.substring(
-                        editorClassName.lastIndexOf(".") + 1);
-                    
-                    if(targetType.isPrimitive()) {
-                        shortEditorClassName =
-                            shortEditorClassName.substring(0,1).toUpperCase()
+
+        editorClass = (Class) registeredEditors.get(targetType);
+
+        if (editorClass == null) {
+            String editorClassName = targetType.getName() + "Editor";
+            ClassLoader loader = targetType.getClassLoader();
+
+            if (loader == null) {
+                loader = Thread.currentThread().getContextClassLoader();
+            }
+
+            try {
+                editorClass = Class.forName(editorClassName, true, loader);
+            } catch (ClassNotFoundException cnfe) {
+                String shortEditorClassName = editorClassName
+                        .substring(editorClassName.lastIndexOf(".") + 1);
+
+                if (targetType.isPrimitive()) {
+                    shortEditorClassName = shortEditorClassName.substring(0, 1)
+                            .toUpperCase()
                             + shortEditorClassName.substring(1);
-                    }
-                    
-                    for (int i = 0; i < path.length; ++i) {
-                        editorClassName = path[i] + "." + shortEditorClassName;
-                        
-                        try {
-                            editorClass = Class.forName(editorClassName, true,
-                                    loader);
-                        } catch (ClassNotFoundException cnfe2) {
-                        } catch (Exception e) {
-                            break;
-                        }
-                    }
-                } catch (Exception e) {
                 }
-            }
-                
-            if (editorClass != null) {
-                try {
-                    editor = (PropertyEditor) editorClass.newInstance();
-                } catch (Exception e) {
+
+                for (int i = 0; i < path.length; ++i) {
+                    editorClassName = path[i] + "." + shortEditorClassName;
+
+                    try {
+                        editorClass = Class.forName(editorClassName, true,
+                                loader);
+                    } catch (ClassNotFoundException cnfe2) {} catch (Exception e) {
+                        break;
+                    }
                 }
-            }
-            
+            } catch (Exception e) {}
         }
+
+        if (editorClass != null) {
+            try {
+                editor = (PropertyEditor) editorClass.newInstance();
+            } catch (Exception e) {}
+        }
+
         return editor;
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java?rev=396796&r1=396795&r2=396796&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyEditorManagerTest.java
Tue Apr 25 00:14:33 2006
@@ -87,9 +87,10 @@
 		PropertyEditor editor = PropertyEditorManager.findEditor(Integer.TYPE);
 	}
 
+    //Regression test for HARMONY-258
 	public void testFindEditor_TypeNull() {
 		try {
-			PropertyEditor editor = PropertyEditorManager.findEditor(null);
+			PropertyEditorManager.findEditor(null);
 			fail("Should throw NullPointerException.");
 		} catch (NullPointerException e) {
 			// expected
@@ -141,6 +142,7 @@
 
 	/*
 	 * registerEditor for type null
+     * Regression test for HARMONY-258
 	 */
 	public void testRegisterEditorType_Null() {
 		try {



Mime
View raw message