[java-identity-provider] branch main updated: Fix null and annotation issues.

Scott Cantor cantor.2 at osu.edu
Tue Nov 22 18:42:26 UTC 2022


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

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

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=5f434db58b06b25f0f80e1ef99abae23880bfb47

The following commit(s) were added to refs/heads/main by this push:
     new 5f434db58 Fix null and annotation issues.
5f434db58 is described below

commit 5f434db58b06b25f0f80e1ef99abae23880bfb47
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Nov 22 13:42:23 2022 -0500

    Fix null and annotation issues.
---
 .../idp/admin/BasicAdministrativeFlowDescriptor.java  |  5 +++--
 .../net/shibboleth/idp/module/AbstractIdPModule.java  | 12 +++++++++---
 .../idp/module/PropertyDrivenIdPModule.java           | 19 +++++++++++++------
 .../idp/plugin/PropertyDrivenIdPPlugin.java           |  3 +++
 .../java/net/shibboleth/idp/module/IdPModuleTest.java |  6 +++++-
 5 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/admin/BasicAdministrativeFlowDescriptor.java b/idp-admin-api/src/main/java/net/shibboleth/idp/admin/BasicAdministrativeFlowDescriptor.java
index 346096888..663bb45ed 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/admin/BasicAdministrativeFlowDescriptor.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/admin/BasicAdministrativeFlowDescriptor.java
@@ -377,13 +377,14 @@ public class BasicAdministrativeFlowDescriptor extends AbstractProfileConfigurat
         
         // Check for string-based representation first, then back off to native objects.
         
-        if (principalServiceManager != null) {
+        final PrincipalServiceManager psm = principalServiceManager;
+        if (psm != null) {
             final Collection<String> stringBasedPrincipals =
                     stringBasedPrincipalsLookupStrategy.apply(profileRequestContext);
             if (stringBasedPrincipals != null && !stringBasedPrincipals.isEmpty()) {
                 final List<Principal> principals = new ArrayList<>(stringBasedPrincipals.size());
                 stringBasedPrincipals.forEach(v -> {
-                    final Principal p = principalServiceManager.principalFromString(v);
+                    final Principal p = psm.principalFromString(v);
                     if (p != null) {
                         principals.add(p);
                     }
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java b/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
index c827e45cb..37e9a8f16 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
@@ -36,6 +36,7 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -165,6 +166,7 @@ public abstract class AbstractIdPModule implements IdPModule {
         }
         
         log.debug("Module {} enabled", getId());
+        assert results != null;
         return results;
     }
 
@@ -190,20 +192,21 @@ public abstract class AbstractIdPModule implements IdPModule {
         }
         
         log.debug("Module {} disabled", getId());
+        assert results != null;
         return results;
     }
 
     /** {@inheritDoc} */
     @Override
     public boolean equals(final Object obj) {
-        return obj instanceof IdPModule && getId().equals(((IdPModule) obj).getId());
+        return obj instanceof IdPModule && Objects.equals(getId(), ((IdPModule) obj).getId());
     }
 
 
     /** {@inheritDoc} */
     @Override
     public int hashCode() {
-        return getId().hashCode();
+        return Constraint.isNotNull(getId(), "ID cannot be null").hashCode();
     }
     
     /** {@inheritDoc} */
@@ -369,13 +372,15 @@ public abstract class AbstractIdPModule implements IdPModule {
                 throws IOException {
             
             final HttpClientContext clientContext = HttpClientContext.create();
+            assert clientContext != null;
             HttpClientSecuritySupport.marshalSecurityParameters(clientContext,
                     moduleContext.getHttpClientSecurityParameters(), true);
             HttpResponse response = null;
             try {
                 log.debug("Module {} fetching HTTP resource {}", getId(), uri);
                 final HttpGet request = new HttpGet(uri);
-                response = moduleContext.getHttpClient().execute(request, clientContext);
+                response = Constraint.isNotNull(
+                        moduleContext.getHttpClient(), "HttpClient cannot be null").execute(request, clientContext);
                 HttpClientSecuritySupport.checkTLSCredentialEvaluated(clientContext, request.getURI().getScheme());
                 if (response.getStatusLine().getStatusCode() != 200) {
                     throw new IOException("HTTP request was unsuccessful");
@@ -384,6 +389,7 @@ public abstract class AbstractIdPModule implements IdPModule {
                 // The response socket should be closed after the stream is closed.
                 final InputStream ret = response.getEntity().getContent();
                 response = null;
+                assert ret != null;
                 return ret;
             } finally {
                 if (response != null && CloseableHttpResponse.class.isInstance(response)) {
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java b/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java
index f9e955514..a64aa0a17 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java
@@ -19,6 +19,7 @@ package net.shibboleth.idp.module;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -137,6 +138,8 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
         locales = Collections.emptyList();
         moduleProperties = new Properties();
         moduleProperties.load(inputStream);
+        moduleId = "";
+        moduleName = "";
         load();
     }
 
@@ -150,6 +153,8 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
     public PropertyDrivenIdPModule(@Nonnull final Properties properties) throws ModuleException {
         locales = Collections.emptyList();
         moduleProperties = Constraint.isNotNull(properties, "Properties cannot be null");
+        moduleId = "";
+        moduleName = "";
         load();
     }
 
@@ -279,10 +284,11 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
     /** {@inheritDoc} */
     @Override
     @Nonnull @NonnullElements public Map<ModuleResource,ResourceResult> enable(
-            @Nullable final ModuleContext moduleContext) throws ModuleException {
+            @Nonnull final ModuleContext moduleContext) throws ModuleException {
         final Map<ModuleResource,ResourceResult> results = super.enable(moduleContext);
         
-        if (moduleContext.getMessageStream() != null) {
+        final PrintStream msgStream = moduleContext.getMessageStream();
+        if (msgStream != null) {
             
             String msg = null;
             
@@ -296,7 +302,7 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
             }
             
             if (msg != null) {
-                moduleContext.getMessageStream().println(msg);
+                msgStream.println(msg);
             }
         }
         
@@ -306,10 +312,11 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
     /** {@inheritDoc} */
     @Override
     @Nonnull @NonnullElements public Map<ModuleResource,ResourceResult> disable(
-            @Nullable final ModuleContext moduleContext, final boolean clean) throws ModuleException {
+            @Nonnull final ModuleContext moduleContext, final boolean clean) throws ModuleException {
         final Map<ModuleResource,ResourceResult> results = super.disable(moduleContext, clean);
 
-        if (moduleContext.getMessageStream() != null) {
+        final PrintStream msgStream = moduleContext.getMessageStream();
+        if (msgStream != null) {
             
             String msg = null;
             
@@ -323,7 +330,7 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
             }
 
             if (msg != null) {
-                moduleContext.getMessageStream().println(msg);
+                msgStream.println(msg);
             }
         }
         
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java
index 6c050fa6b..8de612a08 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java
@@ -203,16 +203,19 @@ public abstract class PropertyDrivenIdPPlugin extends AbstractIdPPlugin {
 
     /** {@inheritDoc} */
     @NonNegative public int getMajorVersion() {
+        assert pluginVersion != null;
         return pluginVersion.getMajor();
     }
 
     /** {@inheritDoc} */
     @NonNegative public int getMinorVersion() {
+        assert pluginVersion != null;
         return pluginVersion.getMinor();
     }
 
     /** {@inheritDoc} */
     @NonNegative public int getPatchVersion() {
+        assert pluginVersion != null;
         return pluginVersion.getPatch();
     }
     
diff --git a/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java b/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java
index 14b2be732..d74f1f24c 100644
--- a/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java
+++ b/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java
@@ -161,7 +161,10 @@ public class IdPModuleTest {
         Assert.assertEquals(testModule.getId(), "idp.test");
         Assert.assertEquals(testModule.getOwnerId(), "idp.test.plugin");
         Assert.assertEquals(testModule.getName(null), "Test module");
-        Assert.assertEquals(testModule.getURL().toString(), "https://wiki.shibboleth.net/confluence/display/IDP4/Home");
+        
+        final String url = testModule.getURL();
+        assert url != null;
+        Assert.assertEquals(url, "https://wiki.shibboleth.net/confluence/display/IDP4/Home");
         
         final Iterator<ModuleResource> resources = testModule.getResources().iterator();
         Assert.assertEquals(testModule.getResources().size(), 2);
@@ -295,6 +298,7 @@ public class IdPModuleTest {
         
         final InputStream certStream = IdPModuleTest.class.getResourceAsStream("/net/shibboleth/idp/module/repo-entity.crt");
         final X509Certificate entityCert = X509Support.decodeCertificate(ByteStreams.toByteArray(certStream));
+        assert entityCert != null;
         final X509Credential entityCredential = new BasicX509Credential(entityCert);
         return new ExplicitKeyTrustEngine(new StaticCredentialResolver(entityCredential));
         

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


More information about the commits mailing list