You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/04/21 08:23:22 UTC

svn commit: r395794 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/PropertyDescriptor.java test/java/tests/api/java/beans/PropertyDescriptorTest.java

Author: mloenko
Date: Thu Apr 20 23:23:20 2006
New Revision: 395794

URL: http://svn.apache.org/viewcvs?rev=395794&view=rev
Log:
fixes for HARMONY-237
PropertyDescriptor constructors throws incorrect (or no) exception

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?rev=395794&r1=395793&r2=395794&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java Thu Apr 20 23:23:20 2006
@@ -45,18 +45,23 @@
     /**
      * @com.intel.drl.spec_ref
      */
-    public PropertyDescriptor(
-            String propertyName,
-            Class beanClass,
-            String getterName,
-            String setterName) throws IntrospectionException {
+    public PropertyDescriptor(String propertyName, Class beanClass,
+            String getterName, String setterName) throws IntrospectionException {
+
         super();
+        if (beanClass == null) {
+            throw new IntrospectionException("Target Bean class is null");
+        }
+        if (propertyName == null || propertyName.length() == 0) {
+            throw new IntrospectionException("bad property name");
+        }
+
         this.beanClass = beanClass;
         this.propertyName = propertyName;
-        
+
         this.setName(propertyName);
         this.setDisplayName(propertyName);
-        
+
         setWriteMethod(beanClass, setterName);
         setReadMethod(beanClass, getterName);
     }
@@ -67,11 +72,15 @@
     public PropertyDescriptor(String propertyName, Method getter, Method setter)
             throws IntrospectionException {
         super();
+        if (propertyName == null) {
+            throw new IntrospectionException("bad property name");
+        }
+
         this.propertyName = propertyName;
-        
+
         this.setName(propertyName);
         this.setDisplayName(propertyName);
-        
+
         setWriteMethod(setter);
         setReadMethod(getter);
     }
@@ -82,6 +91,13 @@
     public PropertyDescriptor(String propertyName, Class beanClass)
             throws IntrospectionException {
         super();
+        if (beanClass == null) {
+            throw new IntrospectionException("Target Bean class is null");
+        }
+        if (propertyName == null || propertyName.length() == 0) {
+            throw new IntrospectionException("bad property name");
+        }
+
         this.propertyName = propertyName;
         
         this.setName(propertyName);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyDescriptorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyDescriptorTest.java?rev=395794&r1=395793&r2=395794&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyDescriptorTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/tests/api/java/beans/PropertyDescriptorTest.java Thu Apr 20 23:23:20 2006
@@ -932,6 +932,55 @@
 		PropertyDescriptor pd = new PropertyDescriptor("fox01", FakeFox01.class);
 	}
 
+    //Regression test for HARMONY-237
+    public void testIntrospectionExpections() {
+        try {
+            PropertyDescriptor pd = new PropertyDescriptor(null,null);
+            fail("Constructor PropertyDescriptor(null,null) should "+
+                 "throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            assertEquals("Target Bean class is null", e.getMessage());
+        }
+        try {
+            PropertyDescriptor pd = new PropertyDescriptor(null,String.class);
+            fail("Constructor PropertyDescriptor(null,String.class) should "+
+                 "throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            assertEquals("bad property name", e.getMessage());
+        }
+        try {
+            PropertyDescriptor pd = new PropertyDescriptor(null,null,null,null);
+            fail("Constructor PropertyDescriptor(null,null,null,null) should "+
+                 "throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            assertEquals("Target Bean class is null", e.getMessage());
+        }
+        try {
+            PropertyDescriptor pd =
+                new PropertyDescriptor(null,String.class,null,null);
+            fail("Constructor "+
+                 "PropertyDescriptor(null,String.class,null,null) should "+
+                 "throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            assertEquals("bad property name", e.getMessage());
+        }
+        try {
+            PropertyDescriptor pd = new PropertyDescriptor(null,null,null);
+            fail("Constructor PropertyDescriptor(null,null,null) should "+
+                 "throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            assertEquals("bad property name", e.getMessage());
+        }
+        try {
+            PropertyDescriptor pd = new PropertyDescriptor("",null,null);
+            fail("Constructor PropertyDescriptor(\"\",null,null) should "+
+                 "throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            assertEquals("bad property name", e.getMessage());
+        }
+    }
+
+    
 	static class FakeFox01 {
 		public String getFox01() {
 			return null;