[java-opensaml] branch main updated: Some null cleanup.

Scott Cantor cantor.2 at osu.edu
Tue Mar 7 22:27:36 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=265e0113e0bb0f7ae1a9302a9d5ca956ccaac3d5

The following commit(s) were added to refs/heads/main by this push:
     new 265e0113e Some null cleanup.
265e0113e is described below

commit 265e0113e0bb0f7ae1a9302a9d5ca956ccaac3d5
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Mar 7 17:27:32 2023 -0500

    Some null cleanup.
---
 .../org/opensaml/core/xml/AbstractXMLObject.java   | 29 +++++------
 .../core/xml/io/AbstractXMLObjectMarshaller.java   | 33 +++++++------
 .../xml/persist/FilesystemLoadSaveManager.java     |  4 +-
 .../core/xml/persist/MapLoadSaveManager.java       |  4 +-
 .../java/org/opensaml/core/xml/util/IDIndex.java   | 32 ++++++-------
 .../xml/util/IndexedXMLObjectChildrenList.java     |  8 ++--
 .../core/xml/util/XMLObjectChildrenList.java       |  2 +-
 .../opensaml/core/xml/util/XMLObjectSupport.java   | 56 ++++++++++++----------
 .../opensaml/saml/config/SAMLConfiguration.java    | 20 ++++----
 .../saml/config/SAMLConfigurationSupport.java      | 19 +++++---
 10 files changed, 111 insertions(+), 96 deletions(-)

diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java
index c09b9540f..1420d2693 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java
@@ -29,12 +29,12 @@ import org.opensaml.core.xml.schema.XSBooleanValue;
 import org.opensaml.core.xml.util.IDIndex;
 import org.opensaml.core.xml.util.XMLObjectSource;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.collection.LockableClassToInstanceMultiMap;
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.xml.QNameSupport;
 import net.shibboleth.shared.xml.XMLConstants;
@@ -48,28 +48,28 @@ public abstract class AbstractXMLObject implements XMLObject {
     @Nonnull private final Logger log = LoggerFactory.getLogger(AbstractXMLObject.class);
 
     /** Parent of this element. */
-    private XMLObject parent;
+    @Nullable private XMLObject parent;
 
     /** The name of this element with namespace and prefix information. */
     @Nonnull private QName elementQname;
 
     /** Schema locations for this XML object. */
-    private String schemaLocation;
+    @Nullable private String schemaLocation;
 
     /** No-namespace schema locations for this XML object. */
-    private String noNamespaceSchemaLocation;
+    @Nullable private String noNamespaceSchemaLocation;
 
     /** The schema type of this element with namespace and prefix information. */
-    private QName typeQname;
+    @Nullable private QName typeQname;
 
     /** DOM Element representation of this object. */
-    private Element dom;
+    @Nullable private Element dom;
     
     /** The value of the <code>xsi:nil</code> attribute. */
-    private  XSBooleanValue nil;
+    @Nullable private XSBooleanValue nil;
     
     /** The namespace manager for this XML object. */
-    private NamespaceManager nsManager;
+    @Nonnull private NamespaceManager nsManager;
     
     /** The multimap holding class-indexed instances of additional info associated with this XML object. */
     @Nonnull private final LockableClassToInstanceMultiMap<Object> objectMetadata;
@@ -78,7 +78,7 @@ public abstract class AbstractXMLObject implements XMLObject {
      * Mapping of ID attributes to XMLObjects in the subtree rooted at this object. This allows constant-time
      * dereferencing of ID-typed attributes within the subtree.
      */
-    private final IDIndex idIndex;
+    @Nonnull private final IDIndex idIndex;
 
     /**
      * Constructor.
@@ -393,8 +393,9 @@ public abstract class AbstractXMLObject implements XMLObject {
     public void releaseChildrenDOM(final boolean propagateRelease) {
         log.trace("Releasing cached DOM reprsentation for children of {} with propagation set to {}",
                 getElementQName(), propagateRelease);
-        if (getOrderedChildren() != null) {
-            for (final XMLObject child : getOrderedChildren()) {
+        final List<XMLObject> children = getOrderedChildren();
+        if (children != null) {
+            for (final XMLObject child : children) {
                 if (child != null) {
                     child.releaseDOM();
                     if (propagateRelease) {
@@ -421,9 +422,9 @@ public abstract class AbstractXMLObject implements XMLObject {
                 propagateRelease);
         final XMLObject parentElement = getParent();
         if (parentElement != null) {
-            parent.releaseDOM();
+            parentElement.releaseDOM();
             if (propagateRelease) {
-                parent.releaseParentDOM(propagateRelease);
+                parentElement.releaseParentDOM(propagateRelease);
             }
         }
     }
@@ -458,7 +459,7 @@ public abstract class AbstractXMLObject implements XMLObject {
     /** {@inheritDoc} */
     @Nullable public XMLObject resolveIDFromRoot(@Nonnull @NotEmpty final String id) {
         XMLObject root = this;
-        while (root.hasParent()) {
+        while (root != null && root.hasParent()) {
             root = root.getParent();
         }
         return root.resolveID(id);
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java
index 2ec724516..1ce50ac68 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java
@@ -24,9 +24,11 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.xml.namespace.QName;
 
+import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.xml.ElementSupport;
 import net.shibboleth.shared.xml.NamespaceSupport;
+import net.shibboleth.shared.xml.ParserPool;
 import net.shibboleth.shared.xml.QNameSupport;
 import net.shibboleth.shared.xml.XMLConstants;
 import net.shibboleth.shared.xml.XMLParserException;
@@ -35,10 +37,12 @@ import org.opensaml.core.xml.AttributeExtensibleXMLObject;
 import org.opensaml.core.xml.Namespace;
 import org.opensaml.core.xml.XMLObject;
 import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
+import org.opensaml.core.xml.schema.XSBooleanValue;
 import org.opensaml.core.xml.util.AttributeMap;
 import org.opensaml.core.xml.util.XMLObjectSupport;
+
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -72,7 +76,11 @@ public abstract class AbstractXMLObjectMarshaller implements Marshaller {
     /** {@inheritDoc} */
     @Nonnull public Element marshall(@Nonnull final XMLObject xmlObject) throws MarshallingException {
         try {
-            final Document document = XMLObjectProviderRegistrySupport.getParserPool().newDocument();
+            final ParserPool parser = XMLObjectProviderRegistrySupport.getParserPool();
+            if (parser == null) {
+                throw new MarshallingException("Unable to obtain ParserPool instance");
+            }
+            final Document document = parser.newDocument();
             return marshall(xmlObject, document);
         } catch (final XMLParserException e) {
             throw new MarshallingException("Unable to create Document to place marshalled elements in", e);
@@ -86,10 +94,6 @@ public abstract class AbstractXMLObjectMarshaller implements Marshaller {
 
         log.trace("Starting to marshall {}", xmlObject.getElementQName());
 
-        if (document == null) {
-            throw new MarshallingException("Given document may not be null");
-        }
-
         log.trace("Checking if {} contains a cached DOM representation", xmlObject.getElementQName());
         domElement = xmlObject.getDOM();
         if (domElement != null) {
@@ -135,10 +139,6 @@ public abstract class AbstractXMLObjectMarshaller implements Marshaller {
         log.trace("Starting to marshall {} as child of {}", xmlObject.getElementQName(), QNameSupport
                 .getNodeQName(parentElement));
 
-        if (parentElement == null) {
-            throw new MarshallingException("Given parent element is null");
-        }
-
         log.trace("Checking if {} contains a cached DOM representation", xmlObject.getElementQName());
         domElement = xmlObject.getDOM();
         if (domElement != null) {
@@ -312,10 +312,8 @@ public abstract class AbstractXMLObjectMarshaller implements Marshaller {
                 }
             }
             log.trace("Adding namespace declaration {} to {}", namespace, xmlObject.getElementQName());
-            final String nsURI = StringSupport.trimOrNull(namespace.getNamespaceURI());
-            final String nsPrefix = StringSupport.trimOrNull(namespace.getNamespacePrefix());
-
-            NamespaceSupport.appendNamespaceDeclaration(domElement, nsURI, nsPrefix);
+            NamespaceSupport.appendNamespaceDeclaration(domElement, namespace.getNamespaceURI(),
+                    namespace.getNamespacePrefix());
         }
     }
 
@@ -344,10 +342,11 @@ public abstract class AbstractXMLObjectMarshaller implements Marshaller {
                     xmlObject.getNoNamespaceSchemaLocation());
         }
         
-        if (xmlObject.isNilXSBoolean() != null && xmlObject.isNil()) {
+        final Boolean nil = xmlObject.isNil();
+        final XSBooleanValue nilValue = xmlObject.isNilXSBoolean();
+        if (nilValue != null && nil != null && nil) {
             log.trace("Setting xsi:nil for XMLObject {} to true", xmlObject.getElementQName());
-            domElement.setAttributeNS(XMLConstants.XSI_NS, XMLConstants.XSI_PREFIX + ":nil",
-                    xmlObject.isNilXSBoolean().toString());
+            domElement.setAttributeNS(XMLConstants.XSI_NS, XMLConstants.XSI_PREFIX + ":nil", nilValue.toString());
         }
 
         final QName type = xmlObject.getSchemaType();
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java
index d01d698df..bae36fb12 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/FilesystemLoadSaveManager.java
@@ -262,7 +262,7 @@ public class FilesystemLoadSaveManager<T extends XMLObject> extends AbstractCond
     }
 
     /** {@inheritDoc} */
-    public Set<String> listKeys() throws IOException {
+    @Nonnull public Set<String> listKeys() throws IOException {
         return java.nio.file.Files.walk(baseDirectory.toPath())
                 .filter(java.nio.file.Files::isRegularFile)
                 .map(Path::getFileName)
@@ -271,7 +271,7 @@ public class FilesystemLoadSaveManager<T extends XMLObject> extends AbstractCond
     }
 
     /** {@inheritDoc} */
-    public Iterable<Pair<String, T>> listAll() throws IOException {
+    @Nonnull public Iterable<Pair<String, T>> listAll() throws IOException {
         return new FileIterable(listKeys());
     }
 
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java
index 725188e71..5359b31e9 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/persist/MapLoadSaveManager.java
@@ -100,12 +100,12 @@ public class MapLoadSaveManager<T extends XMLObject> extends AbstractConditional
     }
 
     /** {@inheritDoc} */
-    public Set<String> listKeys() throws IOException {
+    @Nonnull public Set<String> listKeys() throws IOException {
         return backingMap.keySet();
     }
 
     /** {@inheritDoc} */
-    public Iterable<Pair<String, T>> listAll() throws IOException {
+    @Nonnull public Iterable<Pair<String, T>> listAll() throws IOException {
         final ArrayList<Pair<String,T>> list = new ArrayList<>();
         for (final String key : listKeys()) {
             list.add(new Pair<>(key, load(key)));
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IDIndex.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IDIndex.java
index 22801c99c..3c430cde3 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IDIndex.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IDIndex.java
@@ -17,7 +17,6 @@
 
 package org.opensaml.core.xml.util;
 
-import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 
@@ -26,6 +25,7 @@ import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
 
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.collection.LazyMap;
 import net.shibboleth.shared.logic.Constraint;
 
@@ -65,13 +65,11 @@ public class IDIndex {
      * @param referent the XMLObject child
      */
     public void registerIDMapping(@Nonnull @NotEmpty final String id, @Nonnull final XMLObject referent) {
-        if (id == null) {
-            return;
-        }
-        
         idMappings.put(id, referent);
         if (owner.hasParent()) {
-            owner.getParent().getIDIndex().registerIDMapping(id, referent);
+            final XMLObject parent = owner.getParent();
+            assert parent != null;
+            parent.getIDIndex().registerIDMapping(id, referent);
         }
     }
     
@@ -87,7 +85,9 @@ public class IDIndex {
         
         idMappings.putAll(idIndex.getIDMappings());
         if (owner.hasParent()) {
-            owner.getParent().getIDIndex().registerIDMappings(idIndex);
+            final XMLObject parent = owner.getParent();
+            assert parent != null;
+            parent.getIDIndex().registerIDMappings(idIndex);
         }
     }
     
@@ -97,13 +97,11 @@ public class IDIndex {
      * @param id the ID attribute value of the XMLObject child to deregister
      */  
     public void deregisterIDMapping(@Nonnull @NotEmpty final String id) {
-        if (id == null) {
-            return;
-        }
-        
         idMappings.remove(id);
         if (owner.hasParent()) {
-            owner.getParent().getIDIndex().deregisterIDMapping(id);
+            final XMLObject parent = owner.getParent();
+            assert parent != null;
+            parent.getIDIndex().deregisterIDMapping(id);
         }
     }
     
@@ -121,7 +119,9 @@ public class IDIndex {
             idMappings.remove(id);
         }
         if (owner.hasParent()) {
-            owner.getParent().getIDIndex().deregisterIDMappings(idIndex);
+            final XMLObject parent = owner.getParent();
+            assert parent != null;
+            parent.getIDIndex().deregisterIDMappings(idIndex);
         }
     }
  
@@ -150,7 +150,7 @@ public class IDIndex {
      * @return the set of ID strings which are keys to the index
      */
     @Nonnull public Set<String> getIDs() {
-        return Collections.unmodifiableSet(idMappings.keySet());
+        return CollectionSupport.copyToSet(idMappings.keySet());
     }
     
     /**
@@ -159,7 +159,7 @@ public class IDIndex {
      * @return the ID-to-XMLObject mapping
      */
     @Nonnull protected Map<String, XMLObject> getIDMappings() {
-        return Collections.unmodifiableMap(idMappings);
+        return CollectionSupport.copyToMap(idMappings);
     }
     
-}
+}
\ No newline at end of file
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java
index 410991606..26cf7daf9 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/IndexedXMLObjectChildrenList.java
@@ -274,7 +274,7 @@ class ListView<ElementType extends XMLObject> extends AbstractList<ElementType>
 
     /** {@inheritDoc} */
     @Override
-    public boolean addAll(@Nonnull final Collection<? extends ElementType> c) {
+    public boolean addAll(final Collection<? extends ElementType> c) {
         final boolean result = backingList.addAll(c);
         indexList = backingList.get(index);
         return result;
@@ -282,7 +282,7 @@ class ListView<ElementType extends XMLObject> extends AbstractList<ElementType>
 
     /** {@inheritDoc} */
     @Override
-    public boolean addAll(final int i, @Nonnull final Collection<? extends ElementType> c) {
+    public boolean addAll(final int i, final Collection<? extends ElementType> c) {
         throw new UnsupportedOperationException();
     }
 
@@ -370,7 +370,7 @@ class ListView<ElementType extends XMLObject> extends AbstractList<ElementType>
 
     /** {@inheritDoc} */
     @Override
-    public ElementType set(final int newIndex, @Nonnull final ElementType element) {
+    public ElementType set(final int newIndex, final ElementType element) {
         throw new UnsupportedOperationException();
     }
 
@@ -388,7 +388,7 @@ class ListView<ElementType extends XMLObject> extends AbstractList<ElementType>
 
     /** {@inheritDoc} */
     @Override
-    public <T extends Object> T[] toArray(@Nonnull final T[] a) {
+    public <T extends Object> T[] toArray(final T[] a) {
         return indexList.toArray(a);
     }
 }
\ No newline at end of file
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectChildrenList.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectChildrenList.java
index 8c4ab5411..a5405d88e 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectChildrenList.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectChildrenList.java
@@ -161,7 +161,7 @@ public class XMLObjectChildrenList<ElementType extends XMLObject> extends Abstra
     }
 
     /** {@inheritDoc} */
-    @Nonnull public ElementType remove(final int index) {
+    public ElementType remove(final int index) {
         final ElementType element = elements.remove(index);
 
         if (element != null) {
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
index d30100d88..557ba90cf 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
@@ -28,6 +28,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.xml.namespace.QName;
 
+import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.xml.AttributeSupport;
 import net.shibboleth.shared.xml.ParserPool;
@@ -46,8 +47,9 @@ import org.opensaml.core.xml.io.Marshaller;
 import org.opensaml.core.xml.io.MarshallingException;
 import org.opensaml.core.xml.io.Unmarshaller;
 import org.opensaml.core.xml.io.UnmarshallingException;
+
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -103,7 +105,7 @@ public final class XMLObjectSupport {
      * @throws MarshallingException if original object can not be marshalled
      * @throws UnmarshallingException if cloned object tree can not be unmarshalled
      */
-    public static <T extends XMLObject> T cloneXMLObject(final T originalXMLObject)
+    public static <T extends XMLObject> T cloneXMLObject(@Nonnull final T originalXMLObject)
             throws MarshallingException, UnmarshallingException {
         return cloneXMLObject(originalXMLObject, CloneOutputOption.DropDOM);
     }
@@ -129,16 +131,14 @@ public final class XMLObjectSupport {
     @Nonnull public static <T extends XMLObject> T cloneXMLObject(@Nonnull final T originalXMLObject,
             @Nonnull final CloneOutputOption cloneOutputOption) throws MarshallingException, UnmarshallingException {
         
-        Element origElement = null;
-        if (originalXMLObject.getDOM() == null) {
+        Element origElement = originalXMLObject.getDOM();
+        if (origElement == null) {
             final Marshaller marshaller = getMarshaller(originalXMLObject);
             if (marshaller == null) {
                 throw new MarshallingException("Unable to obtain Marshaller for XMLObject: "
                         + originalXMLObject.getElementQName());
             }
             origElement = marshaller.marshall(originalXMLObject);
-        } else {
-            origElement = originalXMLObject.getDOM();
         }
         
         Element clonedElement = null;
@@ -146,7 +146,11 @@ public final class XMLObjectSupport {
         switch (cloneOutputOption) {
             case RootDOMInNewDocument:
                 try {
-                    final Document newDocument = XMLObjectProviderRegistrySupport.getParserPool().newDocument();
+                    final ParserPool parser = XMLObjectProviderRegistrySupport.getParserPool();
+                    if (parser == null) {
+                        throw new XMLParserException("Unable to obtain ParserPool");
+                    }
+                    final Document newDocument = parser.newDocument();
                     // Note: importNode copies the node tree and does not modify the source document
                     clonedElement = (Element) newDocument.importNode(origElement, true);
                     newDocument.appendChild(clonedElement);
@@ -186,8 +190,8 @@ public final class XMLObjectSupport {
      * @throws XMLParserException if there is a problem parsing the input data
      * @throws UnmarshallingException if there is a problem unmarshalling the parsed DOM
      */
-    @Nonnull public static XMLObject unmarshallFromInputStream(final ParserPool parserPool, final InputStream inputStream)
-            throws XMLParserException, UnmarshallingException {
+    @Nonnull public static XMLObject unmarshallFromInputStream(@Nonnull final ParserPool parserPool,
+            @Nonnull final InputStream inputStream) throws XMLParserException, UnmarshallingException {
         LOG.debug("Parsing InputStream into DOM document");
 
         try {
@@ -227,10 +231,9 @@ public final class XMLObjectSupport {
      * @throws XMLParserException if there is a problem parsing the input data
      * @throws UnmarshallingException if there is a problem unmarshalling the parsed DOM
      */
-    @Nonnull public static XMLObject unmarshallFromReader(final ParserPool parserPool, final Reader reader)
-            throws XMLParserException, UnmarshallingException {
+    @Nonnull public static XMLObject unmarshallFromReader(@Nonnull final ParserPool parserPool,
+            @Nonnull final Reader reader) throws XMLParserException, UnmarshallingException {
         LOG.debug("Parsing Reader into DOM document");
-        
 
         try {
             final Document messageDoc = parserPool.parse(reader);
@@ -270,10 +273,11 @@ public final class XMLObjectSupport {
      */
     @Nonnull public static Element marshall(@Nonnull final XMLObject xmlObject) throws MarshallingException {
         LOG.debug("Marshalling XMLObject");
-        
-        if (xmlObject.getDOM() != null) {
+
+        final Element domElement = xmlObject.getDOM();
+        if (domElement != null) {
             LOG.debug("XMLObject already had cached DOM, returning that element");
-            return xmlObject.getDOM();
+            return domElement;
         }
 
         final Marshaller marshaller = getMarshaller(xmlObject);
@@ -301,8 +305,8 @@ public final class XMLObjectSupport {
      * @param outputStream the OutputStream to which to marshall
      * @throws MarshallingException if there is a problem marshalling the object
      */
-    public static void marshallToOutputStream(final XMLObject xmlObject, final OutputStream outputStream) 
-            throws MarshallingException {
+    public static void marshallToOutputStream(@Nonnull final XMLObject xmlObject,
+            @Nonnull final OutputStream outputStream) throws MarshallingException {
         final Element element = marshall(xmlObject);
         SerializeSupport.writeNode(element, outputStream);
     }
@@ -363,8 +367,9 @@ public final class XMLObjectSupport {
      * @param isIDAttribute flag indicating whether the attribute being marshalled should be handled as an ID-typed
      *            attribute
      */
-    public static void marshallAttribute(final QName attributeName, final List<String> attributeValues,
-            final Element domElement, final boolean isIDAttribute) {
+    public static void marshallAttribute(@Nonnull final QName attributeName,
+            @Nonnull final List<String> attributeValues, @Nonnull final Element domElement,
+            final boolean isIDAttribute) {
         marshallAttribute(attributeName, StringSupport.listToStringValue(attributeValues, " "), domElement,
                 isIDAttribute);
     }
@@ -379,8 +384,8 @@ public final class XMLObjectSupport {
      * @param isIDAttribute flag indicating whether the attribute being marshalled should be handled as an ID-typed
      *            attribute
      */
-    public static void marshallAttribute(final QName attributeName, final String attributeValue,
-            final Element domElement, final boolean isIDAttribute) {
+    public static void marshallAttribute(@Nonnull final QName attributeName, @Nullable final String attributeValue,
+            @Nonnull final Element domElement, final boolean isIDAttribute) {
         final Document document = domElement.getOwnerDocument();
         final Attr attribute = AttributeSupport.constructAttribute(document, attributeName);
         attribute.setValue(attributeValue);
@@ -396,7 +401,8 @@ public final class XMLObjectSupport {
      * @param attributeMap the AttributeMap
      * @param domElement the target Element
      */
-    public static void marshallAttributeMap(final AttributeMap attributeMap, final Element domElement) {
+    public static void marshallAttributeMap(@Nonnull final AttributeMap attributeMap,
+            @Nonnull final Element domElement) {
         final Document document = domElement.getOwnerDocument();
         Attr attribute = null;
         for (final Entry<QName, String> entry : attributeMap.entrySet()) {
@@ -416,7 +422,8 @@ public final class XMLObjectSupport {
      * @param attributeMap the AttributeMap
      * @param domElement the target Element
      */
-    public static void marshallAttributeMapIDness(final AttributeMap attributeMap, final Element domElement) {
+    public static void marshallAttributeMapIDness(@Nonnull final AttributeMap attributeMap,
+            @Nonnull final Element domElement) {
         for (final QName qname : attributeMap.keySet()) {
             if (XMLObjectProviderRegistrySupport.isIDAttribute(qname) || attributeMap.isIDAttribute(qname)) {
                 marshallAttributeIDness(qname, domElement, true);
@@ -460,7 +467,8 @@ public final class XMLObjectSupport {
      * @param attributeMap the target AttributeMap
      * @param attribute the target DOM Attr
      */
-    public static void unmarshallToAttributeMap(@Nonnull final AttributeMap attributeMap, @Nonnull final Attr attribute) {
+    public static void unmarshallToAttributeMap(@Nonnull final AttributeMap attributeMap,
+            @Nonnull final Attr attribute) {
         final QName attribQName = QNameSupport.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(),
                 attribute.getPrefix());
         attributeMap.put(attribQName, attribute.getValue());
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfiguration.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfiguration.java
index 833713b01..81f0818db 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfiguration.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfiguration.java
@@ -31,6 +31,7 @@ import org.opensaml.saml.saml2.binding.artifact.SAML2ArtifactBuilderFactory;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotLive;
 import net.shibboleth.shared.annotation.constraint.Unmodifiable;
+import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.primitive.StringSupport;
 
 /**
@@ -45,13 +46,13 @@ import net.shibboleth.shared.primitive.StringSupport;
 public class SAMLConfiguration {
     
     /** Lowercase string function. */
-    private static Function<String, String> lowercaseFunction = new LowercaseFunction();
+    @Nonnull private static final Function<String, String> lowercaseFunction = new LowercaseFunction();
 
     /** SAML 1 Artifact factory. */
-    private SAML1ArtifactBuilderFactory saml1ArtifactBuilderFactory;
+    @Nullable private SAML1ArtifactBuilderFactory saml1ArtifactBuilderFactory;
 
     /** SAML 2 Artifact factory. */
-    private SAML2ArtifactBuilderFactory saml2ArtifactBuilderFactory;
+    @Nullable private SAML2ArtifactBuilderFactory saml2ArtifactBuilderFactory;
     
     /** The list of schemes allowed to appear in binding URLs when encoding a message. 
      * Defaults to 'http' and 'https'. */
@@ -63,7 +64,7 @@ public class SAMLConfiguration {
      *
      */
     public SAMLConfiguration() {
-        setAllowedBindingURLSchemes(List.of("http", "https"));
+        setAllowedBindingURLSchemes(CollectionSupport.listOf("http", "https"));
     }
 
     /**
@@ -71,7 +72,7 @@ public class SAMLConfiguration {
      * 
      * @return artifact factory for the library
      */
-    public SAML1ArtifactBuilderFactory getSAML1ArtifactBuilderFactory() {
+    @Nullable public SAML1ArtifactBuilderFactory getSAML1ArtifactBuilderFactory() {
         return saml1ArtifactBuilderFactory;
     }
 
@@ -80,7 +81,7 @@ public class SAMLConfiguration {
      * 
      * @param factory artifact factory for the library
      */
-    public void setSAML1ArtifactBuilderFactory(final SAML1ArtifactBuilderFactory factory) {
+    public void setSAML1ArtifactBuilderFactory(@Nullable final SAML1ArtifactBuilderFactory factory) {
         saml1ArtifactBuilderFactory = factory;
     }
 
@@ -89,7 +90,7 @@ public class SAMLConfiguration {
      * 
      * @return artifact factory for the library
      */
-    public SAML2ArtifactBuilderFactory getSAML2ArtifactBuilderFactory() {
+    @Nullable public SAML2ArtifactBuilderFactory getSAML2ArtifactBuilderFactory() {
         return saml2ArtifactBuilderFactory;
     }
 
@@ -98,7 +99,7 @@ public class SAMLConfiguration {
      * 
      * @param factory artifact factory for the library
      */
-    public void setSAML2ArtifactBuilderFactory(final SAML2ArtifactBuilderFactory factory) {
+    public void setSAML2ArtifactBuilderFactory(@Nullable final SAML2ArtifactBuilderFactory factory) {
         saml2ArtifactBuilderFactory = factory;
     }
 
@@ -115,8 +116,7 @@ public class SAMLConfiguration {
      * 
      * @return list of URL schemes allowed to appear in a message
      */
-    @Nonnull @NonnullElements @Unmodifiable @NotLive
-    public List<String> getAllowedBindingURLSchemes() {
+    @Nonnull @NonnullElements @Unmodifiable @NotLive public List<String> getAllowedBindingURLSchemes() {
         return allowedBindingURLSchemes;
     }
 
diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfigurationSupport.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfigurationSupport.java
index f9e3695bf..775c9c2b8 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfigurationSupport.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/config/SAMLConfigurationSupport.java
@@ -19,10 +19,17 @@ package org.opensaml.saml.config;
 
 import java.util.List;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import org.opensaml.core.config.ConfigurationService;
 import org.opensaml.saml.saml1.binding.artifact.SAML1ArtifactBuilderFactory;
 import org.opensaml.saml.saml2.binding.artifact.SAML2ArtifactBuilderFactory;
 
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.annotation.constraint.NotLive;
+import net.shibboleth.shared.annotation.constraint.Unmodifiable;
+
 /**
  * Helper class for working with the registered instance of {@link SAMLConfiguration}, as obtained from
  * the {@link ConfigurationService}.
@@ -38,7 +45,7 @@ public final class SAMLConfigurationSupport {
      * 
      * @return artifact factory for the library
      */
-    public static SAML1ArtifactBuilderFactory getSAML1ArtifactBuilderFactory() {
+    @Nullable public static SAML1ArtifactBuilderFactory getSAML1ArtifactBuilderFactory() {
         return ConfigurationService.get(SAMLConfiguration.class).getSAML1ArtifactBuilderFactory();
     }
 
@@ -47,7 +54,7 @@ public final class SAMLConfigurationSupport {
      * 
      * @param factory artifact factory for the library
      */
-    public static void setSAML1ArtifactBuilderFactory(final SAML1ArtifactBuilderFactory factory) {
+    public static void setSAML1ArtifactBuilderFactory(@Nullable final SAML1ArtifactBuilderFactory factory) {
         ConfigurationService.get(SAMLConfiguration.class).setSAML1ArtifactBuilderFactory(factory);
     }
 
@@ -56,7 +63,7 @@ public final class SAMLConfigurationSupport {
      * 
      * @return artifact factory for the library
      */
-    public static SAML2ArtifactBuilderFactory getSAML2ArtifactBuilderFactory() {
+    @Nullable public static SAML2ArtifactBuilderFactory getSAML2ArtifactBuilderFactory() {
         return ConfigurationService.get(SAMLConfiguration.class).getSAML2ArtifactBuilderFactory();
     }
 
@@ -65,7 +72,7 @@ public final class SAMLConfigurationSupport {
      * 
      * @param factory artifact factory for the library
      */
-    public static void setSAML2ArtifactBuilderFactory(final SAML2ArtifactBuilderFactory factory) {
+    public static void setSAML2ArtifactBuilderFactory(@Nullable final SAML2ArtifactBuilderFactory factory) {
         ConfigurationService.get(SAMLConfiguration.class).setSAML2ArtifactBuilderFactory(factory);
     }
     
@@ -74,7 +81,7 @@ public final class SAMLConfigurationSupport {
      * 
      * @return the list of allowed URL schemes
      */
-    public static List<String> getAllowedBindingURLSchemes() {
+    @Nonnull @NonnullElements @Unmodifiable @NotLive public static List<String> getAllowedBindingURLSchemes() {
         return ConfigurationService.get(SAMLConfiguration.class).getAllowedBindingURLSchemes();
     }
     
@@ -83,7 +90,7 @@ public final class SAMLConfigurationSupport {
      * 
      * @param schemes the new list of allowed URL schemes
      */
-    public static void setAllowedBindingURLSchemes(final List<String>schemes) {
+    public static void setAllowedBindingURLSchemes(@Nullable final List<String>schemes) {
         ConfigurationService.get(SAMLConfiguration.class).setAllowedBindingURLSchemes(schemes);
     }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list