You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2013/02/16 13:19:59 UTC

svn commit: r1446880 - in /commons/sandbox/beanutils2/trunk/src: changes/ main/java/org/apache/commons/beanutils2/ test/java/org/apache/commons/beanutils2/

Author: britter
Date: Sat Feb 16 12:19:59 2013
New Revision: 1446880

URL: http://svn.apache.org/r1446880
Log:
[SANDBOX-442] - Remove IntrospectionException from BeanProperties methods by wrapping it internally

Modified:
    commons/sandbox/beanutils2/trunk/src/changes/changes.xml
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java
    commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java

Modified: commons/sandbox/beanutils2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/changes/changes.xml?rev=1446880&r1=1446879&r2=1446880&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/beanutils2/trunk/src/changes/changes.xml Sat Feb 16 12:19:59 2013
@@ -23,6 +23,9 @@
   </properties>
   <body>
   <release version="0.1" date="201?-??-??" description="First release.">
+    <action dev="britter" type="update" issue="SANDBOX-442">
+      Remove IntrospectionException from BeanProperties methods by wrapping it internally
+    </action>
     <action dev="britter" type="update" issue="SANDBOX-441">
       Handling of types that can not be instantiated in DefaultClassAccessor should 
       be improved to give users better feedback

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java?rev=1446880&r1=1446879&r2=1446880&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/BeanProperties.java Sat Feb 16 12:19:59 2013
@@ -20,7 +20,6 @@ package org.apache.commons.beanutils2;
  */
 
 import java.beans.IndexedPropertyDescriptor;
-import java.beans.IntrospectionException;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Method;
 import java.util.Map;
@@ -34,107 +33,76 @@ public interface BeanProperties<B>
      * @param propertyName the name of the property to be checked.
      * @return true if the current bean type has a property identified by the input name,
      *         false otherwise.
-     * @throws IntrospectionException
      */
-    boolean hasProperty( String propertyName )
-        throws IntrospectionException;
+    boolean hasProperty( String propertyName );
 
     /**
      * Checks if the specified property name identifies a readable property.
      *
      * @param propertyName the name of the property to be checked.
      * @return {@code true}, if the property is readable.
-     * @throws IntrospectionException TODO
-     * @throws NoSuchMethodException TODO
      */
-    boolean isReadable( String propertyName )
-        throws IntrospectionException;
+    boolean isReadable( String propertyName );
 
     /**
      * Checks if the specified property name identifies a writable property.
      *
      * @param propertyName the name of the property to be checked.
      * @return {@code true}, if the property is writable.
-     * @throws IntrospectionException TODO
-     * @throws NoSuchMethodException TODO
      */
-    boolean isWritable( String propertyName )
-        throws IntrospectionException;
+    boolean isWritable( String propertyName );
 
     /**
      *
      * @param propertyName
      * @return
-     * @throws IntrospectionException
-     * @throws NoSuchMethodException
      */
-    PropertyDescriptor getPropertyDescriptor( String propertyName )
-        throws IntrospectionException;
+    PropertyDescriptor getPropertyDescriptor( String propertyName );
 
     /**
      *
      * @param propertyName
      * @return
-     * @throws IntrospectionException
-     * @throws NoSuchMethodException
      */
-    Method getReadPropertyMethod( String propertyName )
-        throws IntrospectionException;
+    Method getReadPropertyMethod( String propertyName );
 
     /**
      *
      * @param name
      * @return
-     * @throws NoSuchMethodException
-     * @throws IntrospectionException
      */
-    Method getWriteMethod( String name )
-        throws IntrospectionException;
+    Method getWriteMethod( String name );
 
     /**
      *
      * @param propertyName
      * @return
-     * @throws NoSuchMethodException
-     * @throws IntrospectionException
      */
-    IndexedPropertyDescriptor getIndexedPropertyDescriptor( String propertyName )
-        throws IntrospectionException;
+    IndexedPropertyDescriptor getIndexedPropertyDescriptor( String propertyName );
 
     /**
      *
      * @param propertyName
      * @return
-     * @throws NoSuchMethodException
-     * @throws IntrospectionException
      */
-    Method getIndexedReadMethod( String propertyName )
-        throws IntrospectionException;
+    Method getIndexedReadMethod( String propertyName );
 
     /**
      *
      * @param propertyName
      * @return
-     * @throws NoSuchMethodException
-     * @throws IntrospectionException
      */
-    Method getIndexedWriteMethod( String propertyName )
-        throws IntrospectionException;
+    Method getIndexedWriteMethod( String propertyName );
 
-    MappedPropertyDescriptor getMappedPropertyDescriptor( String propertyName )
-        throws IntrospectionException;
+    MappedPropertyDescriptor getMappedPropertyDescriptor( String propertyName );
 
-    Method getMappedReadMethod( String propertyName )
-        throws IntrospectionException;
+    Method getMappedReadMethod( String propertyName );
 
     /**
      *
      * @return
-     * @throws IntrospectionException
      */
-    Map<String, PropertyDescriptor> getPropertiesIndex()
-        throws IntrospectionException;
+    Map<String, PropertyDescriptor> getPropertiesIndex();
 
-    Method getMappedWriteMethod( String propertyName )
-        throws IntrospectionException;
+    Method getMappedWriteMethod( String propertyName );
 }

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java?rev=1446880&r1=1446879&r2=1446880&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanAccessor.java Sat Feb 16 12:19:59 2013
@@ -22,7 +22,6 @@ package org.apache.commons.beanutils2;
 import static org.apache.commons.beanutils2.Assertions.checkNotNull;
 import static org.apache.commons.beanutils2.BeanUtils.on;
 
-import java.beans.IntrospectionException;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -54,15 +53,7 @@ final class DefaultBeanAccessor<B>
     public BeanAccessor<?> get( String propertyName )
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
-        Method readMethod;
-        try
-        {
-            readMethod = properties.getReadPropertyMethod( propertyName );
-        }
-        catch ( IntrospectionException e )
-        {
-            throw new NoSuchPropertyException( propertyName, bean.getClass(), e );
-        }
+        Method readMethod = properties.getReadPropertyMethod( propertyName );
 
         Object newBean;
         try
@@ -87,14 +78,7 @@ final class DefaultBeanAccessor<B>
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
         Method indexedReadMethod;
-        try
-        {
-            indexedReadMethod = properties.getIndexedReadMethod( propertyName );
-        }
-        catch ( IntrospectionException e )
-        {
-            throw new NoSuchPropertyException( propertyName, getBeanClass(), e );
-        }
+        indexedReadMethod = properties.getIndexedReadMethod( propertyName );
         return new DefaultIndexedPropertyGetterAccessor<B>( bean, propertyName, indexedReadMethod );
     }
 
@@ -105,14 +89,7 @@ final class DefaultBeanAccessor<B>
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
         Method mappedReadMethod;
-        try
-        {
-            mappedReadMethod = properties.getMappedReadMethod( propertyName );
-        }
-        catch ( IntrospectionException e )
-        {
-            throw new NoSuchPropertyException( propertyName, getBeanClass(), e );
-        }
+        mappedReadMethod = properties.getMappedReadMethod( propertyName );
         return new DefaultMappedPropertyGetterAccessor<B>( bean, propertyName, mappedReadMethod );
     }
 
@@ -143,14 +120,7 @@ final class DefaultBeanAccessor<B>
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
         Method writeMethod;
-        try
-        {
-            writeMethod = properties.getWriteMethod( propertyName );
-        }
-        catch ( IntrospectionException e )
-        {
-            throw new NoSuchPropertyException( propertyName, getBeanClass(), e );
-        }
+        writeMethod = properties.getWriteMethod( propertyName );
         return new DefaultBeanPropertySetter<B>( bean, writeMethod, propertyName );
     }
 
@@ -161,14 +131,7 @@ final class DefaultBeanAccessor<B>
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
         Method indexedWriteMethod;
-        try
-        {
-            indexedWriteMethod = properties.getIndexedWriteMethod( propertyName );
-        }
-        catch ( IntrospectionException e )
-        {
-            throw new NoSuchPropertyException( propertyName, getBeanClass(), e );
-        }
+        indexedWriteMethod = properties.getIndexedWriteMethod( propertyName );
         return new DefaultIndexedPropertySetterAccessor<B>( bean, propertyName, indexedWriteMethod );
     }
 
@@ -179,14 +142,7 @@ final class DefaultBeanAccessor<B>
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
         Method mappedWriteMethod;
-        try
-        {
-            mappedWriteMethod = properties.getMappedWriteMethod( propertyName );
-        }
-        catch ( IntrospectionException e )
-        {
-            throw new NoSuchPropertyException( propertyName, getBeanClass(), e );
-        }
+        mappedWriteMethod = properties.getMappedWriteMethod( propertyName );
         return new DefaultMappedPropertySetterAccessor<B>( bean, propertyName, mappedWriteMethod );
     }
 
@@ -222,16 +178,7 @@ final class DefaultBeanAccessor<B>
     public Map<String, Object> describe()
     {
         Map<String, PropertyDescriptor> propertiesIndex;
-        try
-        {
-            propertiesIndex = properties.getPropertiesIndex();
-        }
-        catch ( IntrospectionException e )
-        {
-            // FIXME can we throw something more specific?
-            throw new BeanReflectionException( e, getBeanClass(),
-                                               "Error while reading out properties index of type '%s'", getBeanClass() );
-        }
+        propertiesIndex = properties.getPropertiesIndex();
         final Map<String, Object> result = new HashMap<String, Object>( propertiesIndex.size() );
 
         for ( Entry<String, PropertyDescriptor> key : propertiesIndex.entrySet() )
@@ -284,16 +231,9 @@ final class DefaultBeanAccessor<B>
 
     private void setIfWritable( String propertyName, Object propertyValue )
     {
-        try
-        {
-            if ( properties.hasProperty( propertyName ) && properties.isWritable( propertyName ) )
-            {
-                set( propertyName ).with( propertyValue );
-            }
-        }
-        catch ( IntrospectionException e )
+        if ( properties.hasProperty( propertyName ) && properties.isWritable( propertyName ) )
         {
-            throw new NoSuchPropertyException( propertyName, getBeanClass(), e );
+            set( propertyName ).with( propertyValue );
         }
     }
 

Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java?rev=1446880&r1=1446879&r2=1446880&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/DefaultBeanProperties.java Sat Feb 16 12:19:59 2013
@@ -19,7 +19,6 @@ package org.apache.commons.beanutils2;
  * under the License.
  */
 
-import static java.lang.String.format;
 import static org.apache.commons.beanutils2.Assertions.checkArgument;
 import static org.apache.commons.beanutils2.Assertions.checkNotNull;
 
@@ -45,12 +44,13 @@ final class DefaultBeanProperties<B>
     // checks
 
     public boolean hasProperty( String propertyName )
-        throws IntrospectionException
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
-        PropertyDescriptor propertyDescriptor = registry.getPropertyDescriptor( beanClass, propertyName );
-
-        if ( propertyDescriptor == null )
+        try
+        {
+            getPropertyDescriptor( propertyName );
+        }
+        catch ( NoSuchPropertyException e )
         {
             return false;
         }
@@ -61,7 +61,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public boolean isReadable( String propertyName )
-        throws IntrospectionException
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
         PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
@@ -89,7 +88,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public boolean isWritable( String propertyName )
-        throws IntrospectionException
     {
         checkNotNull( propertyName, "Parameter 'propertyName' must not be null!" );
         PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
@@ -117,14 +115,20 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public PropertyDescriptor getPropertyDescriptor( String propertyName )
-        throws IntrospectionException
     {
-        PropertyDescriptor propertyDescriptor = registry.getPropertyDescriptor( beanClass, propertyName );
+        PropertyDescriptor propertyDescriptor = null;
+        try
+        {
+            propertyDescriptor = registry.getPropertyDescriptor( beanClass, propertyName );
+        }
+        catch ( IntrospectionException ex )
+        {
+            throw new NoSuchPropertyException( propertyName, beanClass, ex );
+        }
 
         if ( propertyDescriptor == null )
         {
-            throw new IntrospectionException( format( "Property '%s' does not exist in bean of type %s",
-                                                      propertyName, beanClass.getName() ) );
+            throw new NoSuchPropertyException( propertyName, beanClass, null );
         }
 
         return propertyDescriptor;
@@ -134,7 +138,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public Method getReadPropertyMethod( String propertyName )
-        throws IntrospectionException
     {
         PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
 
@@ -145,7 +148,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public Method getWriteMethod( String name )
-        throws IntrospectionException
     {
         PropertyDescriptor propertyDescriptor = getPropertyDescriptor( name );
 
@@ -156,7 +158,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public IndexedPropertyDescriptor getIndexedPropertyDescriptor( String propertyName )
-        throws IntrospectionException
     {
         PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
         checkArgument( propertyDescriptor instanceof IndexedPropertyDescriptor,
@@ -168,7 +169,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public Method getIndexedReadMethod( String propertyName )
-        throws IntrospectionException
     {
         IndexedPropertyDescriptor indexedPropertyDescriptor = getIndexedPropertyDescriptor( propertyName );
 
@@ -179,7 +179,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public Method getIndexedWriteMethod( String propertyName )
-        throws IntrospectionException
     {
         IndexedPropertyDescriptor indexedPropertyDescriptor = getIndexedPropertyDescriptor( propertyName );
 
@@ -210,7 +209,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public MappedPropertyDescriptor getMappedPropertyDescriptor( String propertyName )
-        throws IntrospectionException
     {
         PropertyDescriptor propertyDescriptor = getPropertyDescriptor( propertyName );
         checkArgument( propertyDescriptor instanceof MappedPropertyDescriptor,
@@ -222,7 +220,6 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public Method getMappedReadMethod( String propertyName )
-        throws IntrospectionException
     {
         MappedPropertyDescriptor mappedPropertyDescriptor = getMappedPropertyDescriptor( propertyName );
 
@@ -233,13 +230,18 @@ final class DefaultBeanProperties<B>
      * {@inheritDoc}
      */
     public Map<String, PropertyDescriptor> getPropertiesIndex()
-        throws IntrospectionException
     {
-        return registry.getPropertiesIndex( beanClass );
+        try
+        {
+            return registry.getPropertiesIndex( beanClass );
+        }
+        catch ( IntrospectionException e )
+        {
+            throw new BeanReflectionException( e, beanClass );
+        }
     }
 
     public Method getMappedWriteMethod( String propertyName )
-        throws IntrospectionException
     {
         MappedPropertyDescriptor mappedPropertyDescriptor = getMappedPropertyDescriptor( propertyName );
 

Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java?rev=1446880&r1=1446879&r2=1446880&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java (original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsReadableTestCase.java Sat Feb 16 12:19:59 2013
@@ -21,8 +21,6 @@ import static org.apache.commons.beanuti
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.beans.IntrospectionException;
-
 import org.apache.commons.beanutils2.testbeans.TestBean;
 import org.junit.Test;
 
@@ -36,7 +34,7 @@ public class IsReadableTestCase
         on( TestBean.class ).getProperties().isReadable( null );
     }
 
-    @Test( expected = IntrospectionException.class )
+    @Test( expected = NoSuchPropertyException.class )
     public void isReadbleUnknown()
         throws Exception
     {

Modified: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java?rev=1446880&r1=1446879&r2=1446880&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java (original)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/IsWritableTestCase.java Sat Feb 16 12:19:59 2013
@@ -21,8 +21,6 @@ import static org.apache.commons.beanuti
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.beans.IntrospectionException;
-
 import org.apache.commons.beanutils2.testbeans.TestBean;
 import org.junit.Test;
 
@@ -36,7 +34,7 @@ public class IsWritableTestCase
         on( TestBean.class ).getProperties().isWritable( null );
     }
 
-    @Test( expected = IntrospectionException.class )
+    @Test( expected = NoSuchPropertyException.class )
     public void isWritbleUnknown()
         throws Exception
     {