[java-opensaml COMMIT] /trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java

noreply at shibboleth.net noreply at shibboleth.net
Tue Jul 2 13:00:06 EDT 2013


Author: scantor
Date: Tue Jul  2 13:00:06 2013
New Revision: 3395

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3395&view=rev
Log:
Check for nulls in object clone helper.

Modified:
    trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java

Modified: trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java?rev=3395&r1=3394&r2=3395&view=diff
==============================================================================
--- trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java (original)
+++ trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java Tue Jul  2 13:00:06 2013
@@ -23,6 +23,7 @@
 import java.util.List;
 import java.util.Map.Entry;
 
+import javax.annotation.Nullable;
 import javax.xml.namespace.QName;
 
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -107,15 +108,19 @@
      * 
      * @param <T> the type of object being cloned
      */
-    public static <T extends XMLObject> T cloneXMLObject(T originalXMLObject, boolean rootInNewDocument)
-            throws MarshallingException, UnmarshallingException {
+    @Nullable public static <T extends XMLObject> T cloneXMLObject(@Nullable T originalXMLObject,
+            boolean rootInNewDocument) throws MarshallingException, UnmarshallingException {
         
         if (originalXMLObject == null) {
             return null;
         }
         
-        Marshaller marshaller = getMarshaller(originalXMLObject);
-        Element origElement = marshaller.marshall(originalXMLObject);
+        final Marshaller marshaller = getMarshaller(originalXMLObject);
+        if (marshaller == null) {
+            throw new MarshallingException("Unable to obtain Marshaller for XMLObject: "
+                    + originalXMLObject.getElementQName());
+        }
+        final Element origElement = marshaller.marshall(originalXMLObject);
         
         Element clonedElement = null;
         
@@ -132,10 +137,13 @@
             clonedElement = (Element) origElement.cloneNode(true);
         }
         
-        Unmarshaller unmarshaller = getUnmarshaller(clonedElement);
-        T clonedXMLObject = (T) unmarshaller.unmarshall(clonedElement);
-        
-        return clonedXMLObject;
+        final Unmarshaller unmarshaller = getUnmarshaller(clonedElement);
+        if (unmarshaller == null) {
+            throw new UnmarshallingException("Unable to obtain Unmarshaller for element: "
+                    + QNameSupport.getNodeQName(clonedElement));
+        }
+        
+        return (T) unmarshaller.unmarshall(clonedElement);
     }
     
     /**



More information about the commits mailing list