commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1582524 - /commons/proper/proxy/trunk/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java
Date Thu, 27 Mar 2014 22:37:34 GMT
Author: mbenson
Date: Thu Mar 27 22:37:33 2014
New Revision: 1582524

URL: http://svn.apache.org/r1582524
Log:
use ObjectUtils#clone for cloning functionality

Modified:
    commons/proper/proxy/trunk/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java

Modified: commons/proper/proxy/trunk/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/trunk/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java?rev=1582524&r1=1582523&r2=1582524&view=diff
==============================================================================
--- commons/proper/proxy/trunk/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java
(original)
+++ commons/proper/proxy/trunk/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java
Thu Mar 27 22:37:33 2014
@@ -18,9 +18,10 @@
 package org.apache.commons.proxy2.provider;
 
 import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
 
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.Validate;
+import org.apache.commons.lang3.exception.CloneFailedException;
 import org.apache.commons.lang3.reflect.MethodUtils;
 import org.apache.commons.proxy2.ObjectProvider;
 import org.apache.commons.proxy2.exception.ObjectProviderException;
@@ -69,28 +70,14 @@ public class CloningProvider<T extends C
      * {@inheritDoc}
      */
     @Override
-    @SuppressWarnings("unchecked")
     public T getObject()
     {
         try
         {
-            return (T) MethodUtils.invokeExactMethod(cloneable, "clone");
+            return ObjectUtils.clone(cloneable);
         }
-        catch (IllegalAccessException e)
-        {
-            throw new ObjectProviderException("Class " + cloneable.getClass().getName()
-                    + " does not have a public clone() method.", e);
-        }
-        catch (InvocationTargetException e)
-        {
-            throw new ObjectProviderException("Attempt to clone object of type " + cloneable.getClass().getName()
-                    + " threw an exception.", e);
-        }
-        catch (NoSuchMethodException e)
-        {
-            throw new ObjectProviderException(String.format(
-                    "Class %s does not have a clone() method (should never happen).", cloneable.getClass().getName()),
-                    e);
+        catch (CloneFailedException e) {
+            throw new ObjectProviderException(e.getMessage(), e.getCause());
         }
     }
 



Mime
View raw message