harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r395788 - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/Introspector.java test/java/org/apache/harmony/tests/java/beans/IntrospectorTest.java
Date Fri, 21 Apr 2006 05:59:30 GMT
Author: mloenko
Date: Thu Apr 20 22:59:27 2006
New Revision: 395788

URL: http://svn.apache.org/viewcvs?rev=395788&view=rev
Log:
fixes for HARMONY-257: java.beans.Introspector.getBeanInfo should throw NullPointerException
adding regression test
some clean-up for source and test

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java
    incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/IntrospectorTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java?rev=395788&r1=395787&r2=395788&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java
Thu Apr 20 22:59:27 2006
@@ -16,7 +16,7 @@
 
 /**
  * @author Maxim V. Berkultsev
- * @version $Revision: 1.23.6.3 $
+ * @version $Revision$
  */
 package java.beans;
 
@@ -33,7 +33,7 @@
 
 /**
  * @author Maxim V. Berkultsev
- * @version $Revision: 1.23.6.3 $
+ * @version $Revision$
  */
 
 public class Introspector {
@@ -71,15 +71,17 @@
     public static BeanInfo getBeanInfo(Class beanClass, int flags)
         throws IntrospectionException 
     {
-        BeanInfo result = null;
-        if (flags == USE_ALL_BEANINFO) {
-            result = getBeanInfo(beanClass, null, false, false);    
-        } else if (flags == IGNORE_IMMEDIATE_BEANINFO) {
-            result = getBeanInfo(beanClass, null, true, false);    
-        } else if (flags == IGNORE_ALL_BEANINFO) {
-            result = getBeanInfo(beanClass, null, true, true);    
+        switch (flags) {
+            case USE_ALL_BEANINFO:
+                return getBeanInfo(beanClass, null, false, false);    
+            case IGNORE_IMMEDIATE_BEANINFO:
+                return getBeanInfo(beanClass, null, true, false);
+            case IGNORE_ALL_BEANINFO:
+                return getBeanInfo(beanClass, null, true, true);
+            default:
+                //TODO: verify that default beahvior complies with RI
+                return getBeanInfo(beanClass, null, false, false);
         }
-        return result;
     }
 
     /**
@@ -139,7 +141,7 @@
         boolean ignoreBeanClassBeanInfo, boolean ignoreSuperClassBeanInfo)
     {
         if (beanClass == null) {
-            return null;
+            throw new java.lang.NullPointerException();
         }
 
         BeanInfoWrapper beanInfoWrapper = findBeanInfoClassInCache(beanClass,
@@ -189,8 +191,6 @@
     }
 
     private static Class findBeanInfoClass(Class beanClass) {
-        Object result = null;
-
         String beanClassName = beanClass.getName();
         int idx = beanClassName.lastIndexOf(".");
         String shortBeanInfoClassName = beanClassName.substring(idx + 1,
@@ -701,14 +701,6 @@
         }
     }
     
-    private void clear() {
-        propertyDescriptors = null; 
-        methodDescriptors = null;
-        eventSetDescriptors = null;
-        defaultPropertyIndex = -1;
-        defaultEventIndex = -1;
-    }
-
     private Class beanClass = null;
     private PropertyDescriptor[] propertyDescriptors = null; 
     private MethodDescriptor[] methodDescriptors = null;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/IntrospectorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/IntrospectorTest.java?rev=395788&r1=395787&r2=395788&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/IntrospectorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/tests/java/beans/IntrospectorTest.java
Thu Apr 20 22:59:27 2006
@@ -16,7 +16,7 @@
 
 /**
  * @author Maxim V. Berkultsev
- * @version $Revision: 1.14.6.3 $
+ * @version $Revision$
  */
 package org.apache.harmony.tests.java.beans;
 
@@ -25,13 +25,13 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
+import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.BeanInfo;
 import java.beans.BeanDescriptor;
 import java.beans.EventSetDescriptor;
 import java.beans.MethodDescriptor;
 import java.beans.PropertyDescriptor;
-import java.beans.IntrospectionException;
 import org.apache.harmony.tests.java.beans.auxiliary.ChildBean;
 import org.apache.harmony.tests.java.beans.auxiliary.GrannyBean;
 import org.apache.harmony.tests.java.beans.auxiliary.MisprintBean;
@@ -43,26 +43,27 @@
 
 /**
  * The test checks the class java.beans.Introspector
+ * 
  * @author Maxim V. Berkultsev
  * @version $Revision: 1.14.6.3 $
  */
 
 public class IntrospectorTest extends TestCase {
-    
+
     /**
-     * 
+     *  
      */
     public IntrospectorTest() {
         super();
     }
-    
+
     /**
-     *
+     *  
      */
     public IntrospectorTest(String name) {
         super(name);
     }
-    
+
     /**
      * The test checks the constructor is private
      */
@@ -72,220 +73,202 @@
             fail("No exception is thrown on new Introspector() call");
         } catch (Exception e) {}
     }
-    
+
     /**
      * The test checks the getBeanDescriptor method
      */
-    public void testBeanDescriptor() {
+    public void testBeanDescriptor() throws Exception {
         String[] oldBeanInfoSearchPath = Introspector.getBeanInfoSearchPath();
         try {
-            Introspector.setBeanInfoSearchPath(
-                    new String[] { "java.beans.infos" } );
+            Introspector
+                    .setBeanInfoSearchPath(new String[] { "java.beans.infos" });
             BeanInfo info = Introspector.getBeanInfo(SampleBean.class);
             assertNotNull(info);
             BeanDescriptor descriptor = info.getBeanDescriptor();
             assertNotNull(descriptor);
             assertEquals(SampleBean.class, descriptor.getBeanClass());
-        } catch (Exception e) {
-            fail("Cannot extract bean info from SampleBean class");
         } finally {
             Introspector.setBeanInfoSearchPath(oldBeanInfoSearchPath);
         }
     }
-    
+
     /**
      * The test checks the getMethodDescriptor method
+     * @throws IntrospectionException
      */
-    public void testNonUniqueByNameMethodDescriptors() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(ChildBean.class);
-            assertNotNull(info);
-            MethodDescriptor[] mds = info.getMethodDescriptors();
-            assertNotNull(mds);
-            assertEquals(11, mds.length);
-            assertEquals("wait", mds[8].getName());
-            assertEquals("wait", mds[9].getName());
-            assertEquals("wait", mds[10].getName());
-        } catch (Exception e) {
-            fail("Cannot extract bean info from ChildBean class: "
-                    + e.getClass());
-        }
+    public void testNonUniqueByNameMethodDescriptors() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(ChildBean.class);
+        assertNotNull(info);
+        MethodDescriptor[] mds = info.getMethodDescriptors();
+        assertNotNull(mds);
+        assertEquals(11, mds.length);
+        assertEquals("wait", mds[8].getName());
+        assertEquals("wait", mds[9].getName());
+        assertEquals("wait", mds[10].getName());
     }
-    
+
     /**
      * The test checks the getEventSetDescriptors method
+     * @throws IntrospectionException
      */
-    public void testUnicastEventSetDescriptor() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(SampleBean.class);
-            assertNotNull(info);
-            EventSetDescriptor[] descriptors = info.getEventSetDescriptors();
-            assertNotNull(descriptors);
-            for(int i = 0; i < descriptors.length; ++i) {
-                Method m = descriptors[i].getAddListenerMethod();
-                if(m != null) {
-                    Class[] exceptionTypes = m.getExceptionTypes();
-                    boolean found = false;
-                    
-                    for(int j = 0; j < exceptionTypes.length; ++j) {
-                        if(exceptionTypes[j].equals(
-                                TooManyListenersException.class)) {
-                            assertTrue(descriptors[i].isUnicast());
-                            found = true;
-                            break;
-                        }
-                    }
-                    
-                    if(!found) {
-                        assertEquals(descriptors[i].isUnicast(), false);
+    public void testUnicastEventSetDescriptor() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(SampleBean.class);
+        assertNotNull(info);
+        EventSetDescriptor[] descriptors = info.getEventSetDescriptors();
+        assertNotNull(descriptors);
+        for (int i = 0; i < descriptors.length; ++i) {
+            Method m = descriptors[i].getAddListenerMethod();
+            if (m != null) {
+                Class[] exceptionTypes = m.getExceptionTypes();
+                boolean found = false;
+
+                for (int j = 0; j < exceptionTypes.length; ++j) {
+                    if (exceptionTypes[j]
+                            .equals(TooManyListenersException.class)) {
+                        assertTrue(descriptors[i].isUnicast());
+                        found = true;
+                        break;
                     }
-                        
                 }
+
+                if (!found) {
+                    assertFalse(descriptors[i].isUnicast());
+                }
+
             }
-        } catch (Exception e) {
-            fail("Cannot extract bean info from SampleBean class: "
-                    + e.getClass());
         }
     }
-    
+
     /**
      * The test checks the getEventSetDescriptors method
+     * @throws IntrospectionException
      */
-    public void testEventSetDescriptorWithoutAddListenerMethod() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(OtherBean.class);
-            assertNotNull(info);
-            EventSetDescriptor[] descriptors = info.getEventSetDescriptors();
-            assertNotNull(descriptors);
-            assertEquals(0, descriptors.length);
-        } catch (Exception e) {
-            System.out.println(e.getClass() + ": " + e.getMessage());
-            fail("Cannot extract bean info from SampleBean class");
-        }
+    public void testEventSetDescriptorWithoutAddListenerMethod() throws IntrospectionException
{
+        BeanInfo info = Introspector.getBeanInfo(OtherBean.class);
+        assertNotNull(info);
+        EventSetDescriptor[] descriptors = info.getEventSetDescriptors();
+        assertNotNull(descriptors);
+        assertEquals(0, descriptors.length);
     }
-    
+
     /**
      * The test checks the getEventSetDescriptors method
+     * @throws IntrospectionException
      */
-    public void testIllegalEventSetDescriptor() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(MisprintBean.class);
-            assertNotNull(info);
-            EventSetDescriptor[] descriptors = info.getEventSetDescriptors();
-            assertNotNull(descriptors);
-            assertEquals(0, descriptors.length);
-        } catch (Exception e) {
-            System.out.println(e.getClass() + ": " + e.getMessage());
-            fail("Cannot extract bean info from MisprintBean class");
-        }
+    public void testIllegalEventSetDescriptor() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(MisprintBean.class);
+        assertNotNull(info);
+        EventSetDescriptor[] descriptors = info.getEventSetDescriptors();
+        assertNotNull(descriptors);
+        assertEquals(0, descriptors.length);
     }
-    
+
     /**
      * The test checks the getPropertyDescriptors method
+     * @throws IntrospectionException
      */
-    public void testPropertyDescriptorWithSetMethod() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(OtherBean.class);
-            assertNotNull(info);
-            PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
-            assertNotNull(descriptors);
-            assertEquals(2, descriptors.length);
-            assertEquals("class", descriptors[0].getName());
-            assertEquals("number", descriptors[1].getName());
-        } catch (Exception e) {
-            System.out.println(e.getClass() + ": " + e.getMessage());
-            fail("Cannot extract bean info from SampleBean class");
-        }
+    public void testPropertyDescriptorWithSetMethod() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(OtherBean.class);
+        assertNotNull(info);
+        PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
+        assertNotNull(descriptors);
+        assertEquals(2, descriptors.length);
+        assertEquals("class", descriptors[0].getName());
+        assertEquals("number", descriptors[1].getName());
     }
-    
+
     /**
      * The test checks the getPropertyDescriptors method
+     * @throws IntrospectionException
      */
-    public void testUseAllBeanInfo() {
+    public void testUseAllBeanInfo() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
+                Introspector.USE_ALL_BEANINFO);
+        PropertyDescriptor[] pds = info.getPropertyDescriptors();
+        assertEquals(1, pds.length);
+        assertEquals("childText", pds[0].getName());
+    }
+
+    //Regression test for HARMONY-257
+    public void testGetBeanInfo_NPE() throws IntrospectionException {
         try {
-            BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
-                    Introspector.USE_ALL_BEANINFO);
-            PropertyDescriptor[] pds = info.getPropertyDescriptors();
-            assertEquals(1, pds.length);
-            assertEquals("childText", pds[0].getName());
-        } catch(IntrospectionException ie) {
-            fail(ie.getClass() + ": " + ie.getMessage());
-        }
+            Introspector.getBeanInfo((java.lang.Class) null);
+            fail("getBeanInfo should throw NullPointerException");
+        } catch (NullPointerException e) {}
+
+        try {
+            Introspector.getBeanInfo((java.lang.Class) null,
+                    (java.lang.Class) null);
+            fail("getBeanInfo should throw NullPointerException");
+        } catch (NullPointerException e) {}
+
+        try {
+            Introspector.getBeanInfo((java.lang.Class) null, 0);
+            fail("getBeanInfo should throw NullPointerException");
+        } catch (NullPointerException e) {}
     }
-    
+
     /**
      * The test checks the getPropertyDescriptors method for
      * IGNORE_IMMEDIATE_BEANINFO flag
+     * @throws IntrospectionException
      */
-    public void testIgnoreImmediateBeanInfo() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
-                    Introspector.IGNORE_IMMEDIATE_BEANINFO);
-            PropertyDescriptor[] pds = info.getPropertyDescriptors();
-            assertEquals(1, pds.length);
-            assertEquals("parentText", pds[0].getName());
-        } catch(IntrospectionException ie) {
-            fail(ie.getClass() + ": " + ie.getMessage());
-        }
+    public void testIgnoreImmediateBeanInfo() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
+                Introspector.IGNORE_IMMEDIATE_BEANINFO);
+        PropertyDescriptor[] pds = info.getPropertyDescriptors();
+        assertEquals(1, pds.length);
+        assertEquals("parentText", pds[0].getName());
     }
-    
+
     /**
-     * The test checks the getPropertyDescriptors method for
-     * IGNORE_ALL_BEANINFO flag
-     */
-    public void testIgnoreAllBeanInfo() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
-                    Introspector.IGNORE_ALL_BEANINFO);
-            PropertyDescriptor[] pds = info.getPropertyDescriptors();
-            assertEquals(2, pds.length);
-            assertEquals("class", pds[0].getName());
-            assertEquals("text", pds[1].getName());
-        } catch(IntrospectionException ie) {
-            fail(ie.getClass() + ": " + ie.getMessage());
-        }
+     * The test checks the getPropertyDescriptors method for IGNORE_ALL_BEANINFO
+     * flag
+     * @throws IntrospectionException
+     */
+    public void testIgnoreAllBeanInfo() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
+                Introspector.IGNORE_ALL_BEANINFO);
+        PropertyDescriptor[] pds = info.getPropertyDescriptors();
+        assertEquals(2, pds.length);
+        assertEquals("class", pds[0].getName());
+        assertEquals("text", pds[1].getName());
     }
-    
+
     /**
      * The test checks the getPropertyDescriptors method
+     * @throws IntrospectionException
      */
-    public void testAdditionalBeanInfo() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(StandardBean2.class);
-            PropertyDescriptor[] pds = info.getPropertyDescriptors();
-            assertEquals(1, pds.length);
-            assertEquals("grannyText", pds[0].getName());
-        } catch(IntrospectionException ie) {
-            fail(ie.getClass() + ": " + ie.getMessage());
-        }
+    public void testAdditionalBeanInfo() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(StandardBean2.class);
+        PropertyDescriptor[] pds = info.getPropertyDescriptors();
+        assertEquals(1, pds.length);
+        assertEquals("grannyText", pds[0].getName());
     }
-    
+
     /**
      * The test checks the getPropertyDescriptors for stop class prune
+     * @throws IntrospectionException
      */
-    public void testStopClass() {
-        try {
-            BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
-                    GrannyBean.class);
-            PropertyDescriptor[] pds = info.getPropertyDescriptors();
-            assertEquals(1, pds.length);
-            assertEquals("childText", pds[0].getName());
-        } catch(IntrospectionException ie) {
-            fail(ie.getClass() + ": " + ie.getMessage());
-        }
+    public void testStopClass() throws IntrospectionException {
+        BeanInfo info = Introspector.getBeanInfo(ChildBean.class,
+                GrannyBean.class);
+        PropertyDescriptor[] pds = info.getPropertyDescriptors();
+        assertEquals(1, pds.length);
+        assertEquals("childText", pds[0].getName());
     }
-    
+
     /**
-     * 
+     *  
      */
     public static Test suite() {
         return new TestSuite(IntrospectorTest.class);
     }
-    
+
     /**
-     * 
+     *  
      */
     public static void main(String[] args) {
         TestRunner.run(suite());
     }
-}
+}
\ No newline at end of file



Mime
View raw message