[java-opensaml] 01/05: IDP-2069 Null Handling Task

Rod Widdowson rdw at steadingsoftware.com
Thu Apr 20 14:00:19 UTC 2023


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

rdw 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=dc4e027edf9b8672f7ec9266687e693d5ae40701

commit dc4e027edf9b8672f7ec9266687e693d5ae40701
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Apr 19 13:26:18 2023 +0100

    IDP-2069 Null Handling Task
    
    https://shibboleth.atlassian.net/browse/IDP-2069
    
    Clean all red and a lot of yellow from opensaml-testing
---
 .../testing/TestXMLObjectProviderInitializer.java   |  6 ++++--
 .../core/testing/XMLObjectBaseTestCase.java         | 16 ++++++++++++----
 .../core/testing/XMLObjectProviderBaseTestCase.java | 21 +++++++++++++++------
 .../XMLObjectProviderInitializerBaseTestCase.java   |  3 ++-
 .../org/opensaml/core/xml/mock/SimpleXMLObject.java |  2 +-
 .../core/xml/mock/SimpleXMLObjectBuilder.java       |  5 ++++-
 .../core/xml/mock/SimpleXMLObjectMarshaller.java    |  6 ++++--
 .../core/xml/mock/SimpleXMLObjectUnmarshaller.java  |  8 +++++---
 .../profile/testing/ActionTestingSupport.java       |  4 ++--
 .../opensaml/security/testing/MockTrustEngine.java  |  5 ++++-
 .../storage/testing/StorageServiceTest.java         | 11 +++++++----
 11 files changed, 60 insertions(+), 27 deletions(-)

diff --git a/opensaml-testing/src/main/java/org/opensaml/core/testing/TestXMLObjectProviderInitializer.java b/opensaml-testing/src/main/java/org/opensaml/core/testing/TestXMLObjectProviderInitializer.java
index 6f5f53863..d81b9031e 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/testing/TestXMLObjectProviderInitializer.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/testing/TestXMLObjectProviderInitializer.java
@@ -17,6 +17,8 @@
 
 package org.opensaml.core.testing;
 
+import javax.annotation.Nonnull;
+
 import org.opensaml.core.xml.config.AbstractXMLObjectProviderInitializer;
 
 /**
@@ -25,12 +27,12 @@ import org.opensaml.core.xml.config.AbstractXMLObjectProviderInitializer;
 public class TestXMLObjectProviderInitializer extends AbstractXMLObjectProviderInitializer {
     
     /** Config resources. */
-    private static String[] configs = {
+    @Nonnull private static String[] configs = {
         "/xmltooling-config.xml",
         };
 
     /** {@inheritDoc} */
-    protected String[] getConfigResources() {
+    protected @Nonnull String[] getConfigResources() {
         return configs;
     }
 
diff --git a/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectBaseTestCase.java b/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectBaseTestCase.java
index d31db1efb..c420852b1 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectBaseTestCase.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectBaseTestCase.java
@@ -96,7 +96,7 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
      * @param expectedDOM the expected DOM
      * @param xmlObject the XMLObject to be marshalled and compared against the expected DOM
      */
-    protected void assertXMLEquals(Document expectedDOM, XMLObject xmlObject) {
+    protected void assertXMLEquals(Document expectedDOM, @Nonnull XMLObject xmlObject) {
         assertXMLEquals("Marshalled DOM was not the same as the expected DOM", expectedDOM, xmlObject);
     }
 
@@ -109,11 +109,13 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
      * @param xmlObject the XMLObject to be marshalled and compared against the expected DOM
      */
     protected void assertXMLEquals(String failMessage, Document expectedDOM, XMLObject xmlObject) {
+        assert xmlObject!=null;
         final Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
         if (marshaller == null) {
             Assert.fail("Unable to locate marshaller for " + xmlObject.getElementQName()
                     + " can not perform equality check assertion");
         }
+        assert marshaller!= null;
 
         try {
             final Element generatedDOM = marshaller.marshall(xmlObject, parserPool.newDocument());
@@ -227,10 +229,13 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
     protected void printXML(@Nonnull final XMLObject xmlObject, @Nonnull final String filename) {
         Element elem = null;
         try {
-            elem = marshallerFactory.getMarshaller(xmlObject).marshall(xmlObject);
+            final Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
+            assert marshaller!= null;
+            elem = marshaller.marshall(xmlObject);
         } catch (MarshallingException e) {
             e.printStackTrace();
         }
+        assert elem != null;
         printXML(elem, filename);
     }
 
@@ -272,11 +277,12 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
      * @param qname the QName for which to find the unmarshaller
      * @return the unmarshaller
      */
-    protected Unmarshaller getUnmarshaller(@Nonnull final QName qname) {
+    @Nonnull protected Unmarshaller getUnmarshaller(@Nonnull final QName qname) {
         Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(qname);
         if (unmarshaller == null) {
             Assert.fail("no unmarshaller registered for " + qname);
         }
+        assert unmarshaller!=null;
         return unmarshaller;
     }
 
@@ -301,6 +307,7 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
         if (unmarshaller == null) {
             Assert.fail("no unmarshaller registered for " + QNameSupport.getNodeQName(element));
         }
+        assert unmarshaller!=null;
         return unmarshaller;
     }
 
@@ -312,7 +319,8 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
      * @throws XMLParserException if parsing did not succeed
      */
     @Nonnull protected Document parseXMLDocument(@Nonnull final String xmlFilename) throws XMLParserException {
-        InputStream is = getClass().getResourceAsStream(xmlFilename);
+        final InputStream is = getClass().getResourceAsStream(xmlFilename);
+        assert is != null;
         Document doc = parserPool.parse(is);
         return doc;
     }
diff --git a/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderBaseTestCase.java b/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderBaseTestCase.java
index f4eea3565..cdd295a8c 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderBaseTestCase.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderBaseTestCase.java
@@ -17,8 +17,11 @@
 
 package org.opensaml.core.testing;
 
+import javax.annotation.Nonnull;
+
 import org.opensaml.core.xml.XMLObject;
 import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
+import org.opensaml.core.xml.io.Marshaller;
 import org.opensaml.core.xml.io.MarshallingException;
 import org.opensaml.core.xml.util.XMLObjectSupport;
 import org.testng.Assert;
@@ -28,6 +31,7 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import net.shibboleth.shared.xml.ElementSupport;
+import net.shibboleth.shared.xml.ParserPool;
 import net.shibboleth.shared.xml.XMLParserException;
 
 /**
@@ -67,6 +71,7 @@ public abstract class XMLObjectProviderBaseTestCase extends XMLObjectBaseTestCas
     /** The result of parsing the invalid file. */
     protected Document invalidDOM;
 
+    @SuppressWarnings("null")
     @BeforeClass
 	protected void initXMLObjectProviderTestingSupprt() throws Exception {
         if (singleElementFile != null) {
@@ -161,25 +166,29 @@ public abstract class XMLObjectProviderBaseTestCase extends XMLObjectBaseTestCas
      * @throws MarshallingException
      * @throws XMLParserException
      * */
-    public void testAttributeIDnessMarshall(final XMLObject target, final String idValue) throws MarshallingException, XMLParserException {
+    public void testAttributeIDnessMarshall(@Nonnull final XMLObject target, final String idValue) throws MarshallingException, XMLParserException {
         // Test marshall of newly constructed object
-        Element origDOM = XMLObjectSupport.getMarshaller(target).marshall(target);
+        Marshaller marshaller = XMLObjectSupport.getMarshaller(target);
+        assert marshaller!=null;
+        Element origDOM = marshaller.marshall(target);
         Element resolvedDOM = origDOM.getOwnerDocument().getElementById(idValue);
         Assert.assertNotNull(resolvedDOM);
         Assert.assertTrue(origDOM.isSameNode(resolvedDOM));
 
         // Remarshall existing DOM into new Document
-        Document newDocument = XMLObjectProviderRegistrySupport.getParserPool().newDocument();
-        origDOM = XMLObjectSupport.getMarshaller(target).marshall(target, newDocument);
+        final ParserPool parserPool =  XMLObjectProviderRegistrySupport.getParserPool();
+        assert parserPool!=null;
+        Document newDocument = parserPool.newDocument();
+        origDOM = marshaller.marshall(target, newDocument);
         resolvedDOM = newDocument.getElementById(idValue);
         Assert.assertNotNull(resolvedDOM);
         Assert.assertTrue(origDOM.isSameNode(resolvedDOM));
 
         // Remarshall existing DOM as child of new parent Element in new Document
-        newDocument = XMLObjectProviderRegistrySupport.getParserPool().newDocument();
+        newDocument = parserPool.newDocument();
         Element parent = ElementSupport.constructElement(newDocument, "urn:test:foo", "Foo", "foo");
         ElementSupport.setDocumentElement(newDocument, parent);
-        origDOM = XMLObjectSupport.getMarshaller(target).marshall(target, parent);
+        origDOM = marshaller.marshall(target, parent);
         resolvedDOM = newDocument.getElementById(idValue);
         Assert.assertNotNull(resolvedDOM);
         Assert.assertTrue(origDOM.isSameNode(resolvedDOM));
diff --git a/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderInitializerBaseTestCase.java b/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderInitializerBaseTestCase.java
index 9cf902fe0..82884cbcd 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderInitializerBaseTestCase.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/testing/XMLObjectProviderInitializerBaseTestCase.java
@@ -47,9 +47,10 @@ public abstract class XMLObjectProviderInitializerBaseTestCase extends Initializ
         initializer.init();
         
         registry = ConfigurationService.get(XMLObjectProviderRegistry.class);
-        Assert.assertNotNull(registry, "Registry was null");
+        assert registry!= null;
         
         for (QName providerName : getTestedProviders()) {
+            assert providerName!=null;
             Assert.assertNotNull(registry.getBuilderFactory().getBuilder(providerName),
                     "Builder  for provider '" + providerName + "'was null");
             Assert.assertNotNull(registry.getUnmarshallerFactory().getUnmarshaller(providerName),
diff --git a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObject.java b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObject.java
index 41f433ebd..a61502337 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObject.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObject.java
@@ -142,7 +142,7 @@ public class SimpleXMLObject extends AbstractXMLObject  implements ElementExtens
     
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nonnull public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
+    @Nonnull public List<XMLObject> getUnknownXMLObjects(@Nonnull QName typeOrName) {
         return (List<XMLObject>) unknownXMLObjects.subList(typeOrName);
     }
 
diff --git a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectBuilder.java b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectBuilder.java
index 9d08d8356..4a084264c 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectBuilder.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectBuilder.java
@@ -21,6 +21,9 @@
 
 package org.opensaml.core.xml.mock;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import org.opensaml.core.xml.AbstractXMLObjectBuilder;
 
 /**
@@ -33,7 +36,7 @@ public class SimpleXMLObjectBuilder extends AbstractXMLObjectBuilder<SimpleXMLOb
     }
 
     /** {@inheritDoc} */
-    public SimpleXMLObject buildObject(String namespaceURI, String localName, String namespacePrefix) {
+    public @Nonnull SimpleXMLObject buildObject(@Nullable String namespaceURI, @Nonnull String localName, @Nullable String namespacePrefix) {
         return new SimpleXMLObject(namespaceURI, localName, namespacePrefix);
     }
 }
\ No newline at end of file
diff --git a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectMarshaller.java b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectMarshaller.java
index fd112c70a..f13a78656 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectMarshaller.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectMarshaller.java
@@ -17,6 +17,8 @@
 
 package org.opensaml.core.xml.mock;
 
+import javax.annotation.Nonnull;
+
 import org.opensaml.core.xml.XMLObject;
 import org.opensaml.core.xml.io.AbstractXMLObjectMarshaller;
 import org.opensaml.core.xml.io.MarshallingException;
@@ -29,7 +31,7 @@ import org.w3c.dom.Element;
 public class SimpleXMLObjectMarshaller extends AbstractXMLObjectMarshaller {
 
     /** {@inheritDoc} */
-    protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
+    protected void marshallAttributes(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) throws MarshallingException {
         SimpleXMLObject simpleXMLObject = (SimpleXMLObject) xmlObject;
 
         if (simpleXMLObject.getId() != null) {
@@ -42,7 +44,7 @@ public class SimpleXMLObjectMarshaller extends AbstractXMLObjectMarshaller {
     }
 
     /** {@inheritDoc} */
-    protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {
+    protected void marshallElementContent(@Nonnull XMLObject xmlObject, @Nonnull Element domElement) throws MarshallingException {
         SimpleXMLObject simpleXMLObject = (SimpleXMLObject) xmlObject;
 
         if (simpleXMLObject.getValue() != null) {
diff --git a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectUnmarshaller.java b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectUnmarshaller.java
index 9d3068b6e..0a5602c34 100644
--- a/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectUnmarshaller.java
+++ b/opensaml-testing/src/main/java/org/opensaml/core/xml/mock/SimpleXMLObjectUnmarshaller.java
@@ -21,6 +21,8 @@
 
 package org.opensaml.core.xml.mock;
 
+import javax.annotation.Nonnull;
+
 import org.opensaml.core.xml.XMLObject;
 import org.opensaml.core.xml.io.AbstractXMLObjectUnmarshaller;
 import org.opensaml.core.xml.io.UnmarshallingException;
@@ -33,7 +35,7 @@ import org.w3c.dom.Attr;
 public class SimpleXMLObjectUnmarshaller extends AbstractXMLObjectUnmarshaller {
 
     /** {@inheritDoc} */
-    protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
+    protected void processChildElement(@Nonnull XMLObject parentXMLObject, @Nonnull XMLObject childXMLObject)
             throws UnmarshallingException {
 
         SimpleXMLObject simpleXMLObject = (SimpleXMLObject) parentXMLObject;
@@ -46,7 +48,7 @@ public class SimpleXMLObjectUnmarshaller extends AbstractXMLObjectUnmarshaller {
     }
 
     /** {@inheritDoc} */
-    protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
+    protected void processAttribute(@Nonnull XMLObject xmlObject, @Nonnull Attr attribute) throws UnmarshallingException {
         SimpleXMLObject simpleXMLObject = (SimpleXMLObject) xmlObject;
 
         if (attribute.getLocalName().equals(SimpleXMLObject.ID_ATTRIB_NAME)) {
@@ -58,7 +60,7 @@ public class SimpleXMLObjectUnmarshaller extends AbstractXMLObjectUnmarshaller {
     }
 
     /** {@inheritDoc} */
-    protected void processElementContent(XMLObject xmlObject, String elementContent) {
+    protected void processElementContent(@Nonnull XMLObject xmlObject, @Nonnull String elementContent) {
         SimpleXMLObject simpleXMLObject = (SimpleXMLObject) xmlObject;
 
         simpleXMLObject.setValue(elementContent);
diff --git a/opensaml-testing/src/main/java/org/opensaml/profile/testing/ActionTestingSupport.java b/opensaml-testing/src/main/java/org/opensaml/profile/testing/ActionTestingSupport.java
index 3c523fadd..284bc73b9 100644
--- a/opensaml-testing/src/main/java/org/opensaml/profile/testing/ActionTestingSupport.java
+++ b/opensaml-testing/src/main/java/org/opensaml/profile/testing/ActionTestingSupport.java
@@ -49,7 +49,7 @@ public class ActionTestingSupport {
      */
     public static void assertEvent(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final Object event) {
         EventContext ctx = profileRequestContext.getSubcontext(EventContext.class);
-        Assert.assertNotNull(ctx);
+        assert ctx!=null;
         Assert.assertEquals(ctx.getEvent(), event);
     }
 
@@ -60,7 +60,7 @@ public class ActionTestingSupport {
      */
     public static void assertProceedEvent(@Nonnull final ProfileRequestContext profileRequestContext) {
         EventContext ctx = profileRequestContext.getSubcontext(EventContext.class);
-        Assert.assertTrue(ctx == null || ctx.getEvent().equals(EventIds.PROCEED_EVENT_ID));
+        Assert.assertTrue(ctx == null || EventIds.PROCEED_EVENT_ID.equals(ctx.getEvent()));
     }
     
 }
\ No newline at end of file
diff --git a/opensaml-testing/src/main/java/org/opensaml/security/testing/MockTrustEngine.java b/opensaml-testing/src/main/java/org/opensaml/security/testing/MockTrustEngine.java
index 467f13ee2..5fc0c76ee 100644
--- a/opensaml-testing/src/main/java/org/opensaml/security/testing/MockTrustEngine.java
+++ b/opensaml-testing/src/main/java/org/opensaml/security/testing/MockTrustEngine.java
@@ -17,6 +17,9 @@
 
 package org.opensaml.security.testing;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import org.opensaml.security.SecurityException;
 import org.opensaml.security.trust.TrustEngine;
 
@@ -37,7 +40,7 @@ public class MockTrustEngine<TokenType> implements TrustEngine<TokenType> {
     }
 
     /** {@inheritDoc} */
-    public boolean validate(TokenType token, CriteriaSet trustBasisCriteria) throws SecurityException {
+    public boolean validate(@Nonnull TokenType token, @Nullable CriteriaSet trustBasisCriteria) throws SecurityException {
         if (throwable != null) {
             if (SecurityException.class.isInstance(throwable)) {
                 throw SecurityException.class.cast(throwable);
diff --git a/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java b/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java
index aa4651653..01f3097cc 100644
--- a/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java
+++ b/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java
@@ -44,7 +44,7 @@ import net.shibboleth.shared.component.InitializableComponent;
 /**
  * Test of {@link StorageService} implementations.
  */
- at SuppressWarnings("javadoc")
+ at SuppressWarnings({"javadoc", "null"})
 public abstract class StorageServiceTest {
     
     protected SecureRandom random;
@@ -92,7 +92,7 @@ public abstract class StorageServiceTest {
         
         for (int i = 1; i <= 100; i++) {
             StorageRecord<?> rec = shared.read(context, Integer.toString(i));
-            Assert.assertNotNull(rec);
+            assert rec!=null;
             Assert.assertEquals(rec.getValue(), Integer.toString(i + 1));
         }
 
@@ -103,7 +103,7 @@ public abstract class StorageServiceTest {
 
         for (int i = 1; i <= 100; i++) {
             StorageRecord<?> rec = shared.read(context, Integer.toString(i));
-            Assert.assertNotNull(rec);
+            assert rec!=null;
             Assert.assertEquals(rec.getValue(), Integer.toString(i + 2));
         }
 
@@ -156,7 +156,7 @@ public abstract class StorageServiceTest {
         }
         
         StorageRecord<?> rec = shared.read(context, key);
-        Assert.assertNotNull(rec);
+        assert rec!=null;
         Assert.assertEquals(rec.getVersion(), 2);
     }
     
@@ -169,16 +169,19 @@ public abstract class StorageServiceTest {
 
         shared.create(context, context, value, expiration);
         StorageRecord<Object> rec = shared.read(context, context);
+        assert rec!=null;
         assertEquals(rec.getValue(), value);
         assertEquals(rec.getExpiration(), expiration);
 
         shared.updateExpiration(context, context, expiration+50000);
         rec = shared.read(context, context);
+        assert rec!=null;
         assertEquals(rec.getValue(), value);
         assertNotEquals(rec.getExpiration(), expiration);
 
         shared.update(context, context, newValue, expiration+100000);
         rec = shared.read(context, context);
+        assert rec!=null;
         assertEquals(rec.getValue(), newValue);
         assertNotEquals(rec.getExpiration(), expiration);
     }

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


More information about the commits mailing list