[java-shib-shared] branch main updated: Fix null and annotation bugs.

Scott Cantor cantor.2 at osu.edu
Mon Nov 7 20:50:39 UTC 2022


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

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

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=8e277c08619a95b48947e1cd194069051b54ac4b

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

commit 8e277c08619a95b48947e1cd194069051b54ac4b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Nov 7 15:50:37 2022 -0500

    Fix null and annotation bugs.
---
 .../resource/FileBackedHTTPResource.java           |  4 +-
 .../spring/httpclient/resource/HTTPResource.java   | 36 +++++++++--------
 .../shared/spring/servlet/impl/ChainingFilter.java |  7 ++--
 .../servlet/impl/SameSiteCookieHeaderFilter.java   |  2 +-
 .../httpclient/resource/HTTPResourceTest.java      | 13 +++++--
 .../HttpServletRequestResponseContextTest.java     | 14 ++++---
 .../impl/SameSiteCookieHeaderFilterTest.java       |  9 +++--
 .../httpclient/ContextHandlingHttpClient.java      | 45 +++++++++++-----------
 .../shared/httpclient/HttpClientBuilder.java       | 29 +++++++++++++-
 .../shared/net/SimpleURLCanonicalizer.java         | 14 +++----
 .../java/net/shibboleth/shared/net/URLBuilder.java |  2 +-
 .../shared/servlet/impl/StubbedFilter.java         | 10 +++--
 .../shibboleth/shared/net/CookieManagerTest.java   |  7 ++--
 .../net/shibboleth/shared/net/IPRangeTest.java     | 29 ++++++++++----
 14 files changed, 141 insertions(+), 80 deletions(-)

diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/FileBackedHTTPResource.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/FileBackedHTTPResource.java
index a91aff5f..ca9b798e 100644
--- a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/FileBackedHTTPResource.java
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/FileBackedHTTPResource.java
@@ -170,13 +170,13 @@ public class FileBackedHTTPResource extends HTTPResource {
     }
 
     /** {@inheritDoc} */
-    @Override public HTTPResource createRelative(final String relativePath) throws IOException {
+    @Override @Nonnull public HTTPResource createRelative(@Nonnull final String relativePath) throws IOException {
         log.warn("{}: Relative resources are not file backed");
         return super.createRelative(relativePath);
     }
 
     /** {@inheritDoc} */
-    @Override public String getDescription() {
+    @Override @Nonnull public String getDescription() {
         String urlAsString;
         try {
             urlAsString = getURL().toString();
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java
index 97b8240f..d20eff37 100644
--- a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResource.java
@@ -161,18 +161,20 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
     @Override @Nonnull public InputStream getInputStream() throws IOException {
         final HttpGet httpGet = new HttpGet(resourceURL.toExternalForm());
         final HttpCacheContext context = buildHttpClientContext();
+
+        final HttpClientContextHandler contextHandler = httpClientContextHandler;
         
-        if (httpClientContextHandler != null) {
+        if (contextHandler != null) {
             log.debug("Invoking HttpClientContextHandler prior to execution");
-            httpClientContextHandler.invokeBefore(context, httpGet);
+            contextHandler.invokeBefore(context, httpGet);
         }
         
         log.debug("Attempting to get data from remote resource '{}'", resourceURL);
         final HttpResponse response = httpClient.execute(httpGet, context);
         
-        if (httpClientContextHandler != null) {
+        if (contextHandler != null) {
             log.debug("Invoking HttpClientContextHandler after execution");
-            httpClientContextHandler.invokeAfter(context, httpGet);
+            contextHandler.invokeAfter(context, httpGet);
         }
         
         reportCachingStatus(context);
@@ -225,12 +227,12 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
     }
 
     /** {@inheritDoc} */
-    @Override public URL getURL() throws IOException {
+    @Override @Nonnull public URL getURL() throws IOException {
         return resourceURL;
     }
 
     /** {@inheritDoc} */
-    @Override public URI getURI() throws IOException {
+    @Override @Nonnull public URI getURI() throws IOException {
         try {
             return resourceURL.toURI();
         } catch (final URISyntaxException ex) {
@@ -239,7 +241,7 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
     }
 
     /** {@inheritDoc} Based on {@link org.springframework.core.io.UrlResource}. */
-    @Override public File getFile() throws IOException {
+    @Override @Nonnull public File getFile() throws IOException {
         throw new FileNotFoundException("HTTPResource cannot be resolved to absolute file path "
                 + "because it does not reside in the file system: " + resourceURL);
     }
@@ -259,16 +261,18 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
         try {
             final HttpCacheContext context = buildHttpClientContext();
             
-            if (httpClientContextHandler != null) {
+            final HttpClientContextHandler contextHandler = httpClientContextHandler;
+            
+            if (contextHandler != null) {
                 log.debug("Invoking HttpClientContextHandler prior to execution");
-                httpClientContextHandler.invokeBefore(context, httpRequest);
+                contextHandler.invokeBefore(context, httpRequest);
             }
             
             httpResponse = httpClient.execute(httpRequest, context);
             
-            if (httpClientContextHandler != null) {
+            if (contextHandler != null) {
                 log.debug("Invoking HttpClientContextHandler after execution");
-                httpClientContextHandler.invokeAfter(context, httpRequest);
+                contextHandler.invokeAfter(context, httpRequest);
             }
             
             reportCachingStatus(context);
@@ -335,7 +339,7 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
     }
 
     /** {@inheritDoc} Based on {@link org.springframework.core.io.UrlResource}. */
-    @Override public HTTPResource createRelative(final String relativePath) throws IOException {
+    @Override @Nonnull public HTTPResource createRelative(@Nonnull final String relativePath) throws IOException {
         final String path;
         if (relativePath.startsWith("/")) {
             path = relativePath.substring(1);
@@ -353,8 +357,8 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
     }
 
     /** {@inheritDoc} */
-    @Override public net.shibboleth.shared.resource.Resource createRelativeResource(
-            final String relativePath) throws IOException {
+    @Override @Nonnull public net.shibboleth.shared.resource.Resource createRelativeResource(
+            @Nonnull final String relativePath) throws IOException {
 
         return createRelative(relativePath);
     }
@@ -365,12 +369,12 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
      * @see java.net.URL#getFile()
      * @see java.io.File#getName()
      */
-    @Override public String getFilename() {
+    @Override @Nullable public String getFilename() {
         return new File(resourceURL.getFile()).getName();
     }
 
     /** {@inheritDoc} */
-    @Override public String getDescription() {
+    @Override @Nonnull public String getDescription() {
         final StringBuilder builder = new StringBuilder("HTTPResource [").append(resourceURL.toString()).append(']');
         return builder.toString();
 
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/ChainingFilter.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/ChainingFilter.java
index b8c40aac..ff4ba25a 100644
--- a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/ChainingFilter.java
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/ChainingFilter.java
@@ -76,10 +76,10 @@ public class ChainingFilter implements Filter {
     public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
             throws IOException, ServletException {
         
-        if (filters == null || filters.isEmpty()) {
-            chain.doFilter(request, response);
-        } else {
+        if (filters != null && !filters.isEmpty()) {
             new Chain(chain).doFilter(request, response);
+        } else {
+            chain.doFilter(request, response);
         }
     }
 
@@ -98,6 +98,7 @@ public class ChainingFilter implements Filter {
          * @param outer outer filter chain
          */
         public Chain(@Nonnull final FilterChain outer) {
+            assert(filters != null);
             iterator = filters.iterator();
             outerChain = outer;
         }
diff --git a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilter.java b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilter.java
index 1602688d..41e3747e 100644
--- a/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilter.java
+++ b/shib-networking-spring/src/main/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilter.java
@@ -173,7 +173,7 @@ public class SameSiteCookieHeaderFilter extends AbstractConditionalFilter implem
     }
     
     /** {@inheritDoc} */
-    public void init(@Nonnull final FilterConfig filterConfig) throws ServletException {
+    public void init(final FilterConfig filterConfig) throws ServletException {
     }
     
     /** {@inheritDoc} */
diff --git a/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResourceTest.java b/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResourceTest.java
index 60dd6cb5..77c01f5e 100644
--- a/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResourceTest.java
+++ b/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/httpclient/resource/HTTPResourceTest.java
@@ -30,6 +30,7 @@ import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.core.io.ClassPathResource;
 import org.testng.Assert;
@@ -172,7 +173,6 @@ public class HTTPResourceTest {
         final GenericApplicationContext context =
                 getContext("classpath:/net/shibboleth/shared/spring/httpclient/resource/MemBackedHTTPBean.xml", null);
         try {
-
             final Collection<TestHTTPResource> beans = context.getBeansOfType(TestHTTPResource.class).values();
             Assert.assertEquals(beans.size(), 1);
 
@@ -184,7 +184,10 @@ public class HTTPResourceTest {
 
             Assert.assertEquals(what.getLastCacheResponseStatus(), CacheResponseStatus.CACHE_HIT);
         } finally {
-            ((GenericApplicationContext) context.getParent()).close();
+            final ApplicationContext parent = context.getParent();
+            if (parent instanceof GenericApplicationContext) {
+                ((GenericApplicationContext) parent).close();
+            }
             context.close();
         }
     }
@@ -221,8 +224,10 @@ public class HTTPResourceTest {
                 emptyDir(theDir);
             }
             if (null != context) {
-                ((GenericApplicationContext) context.getParent()).close();
-                context.close();
+                final ApplicationContext parent = context.getParent();
+                if (parent instanceof GenericApplicationContext) {
+                    ((GenericApplicationContext) parent).close();
+                }
             }
         }
     }
diff --git a/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/HttpServletRequestResponseContextTest.java b/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/HttpServletRequestResponseContextTest.java
index e57dabac..9105d5c3 100644
--- a/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/HttpServletRequestResponseContextTest.java
+++ b/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/HttpServletRequestResponseContextTest.java
@@ -65,12 +65,16 @@ public class HttpServletRequestResponseContextTest {
        Assert.assertNotNull(HttpServletRequestResponseContext.getRequest()); 
        Assert.assertNotNull(HttpServletRequestResponseContext.getResponse()); 
        
-       Assert.assertEquals(HttpServletRequestResponseContext.getRequest().getMethod(), "GET");
-       Assert.assertEquals(HttpServletRequestResponseContext.getRequest().getRequestURI(), "/foo");
-       Assert.assertEquals(HttpServletRequestResponseContext.getRequest().getHeader("MyRequestHeader"), "MyRequestHeaderValue");
-       Assert.assertEquals(HttpServletRequestResponseContext.getRequest().getParameter("MyParam"), "MyParamValue");
+       final HttpServletRequest request = HttpServletRequestResponseContext.getRequest();
+       assert(request != null);
+       Assert.assertEquals(request.getMethod(), "GET");
+       Assert.assertEquals(request.getRequestURI(), "/foo");
+       Assert.assertEquals(request.getHeader("MyRequestHeader"), "MyRequestHeaderValue");
+       Assert.assertEquals(request.getParameter("MyParam"), "MyParamValue");
        
-       Assert.assertTrue(HttpServletRequestResponseContext.getResponse().containsHeader("MyResponseHeader"));
+       final HttpServletResponse response = HttpServletRequestResponseContext.getResponse();
+       assert(response != null);
+       Assert.assertTrue(response.containsHeader("MyResponseHeader"));
        
        HttpServletRequestResponseContext.clearCurrent();
        
diff --git a/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilterTest.java b/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilterTest.java
index 5d81d525..4741fb39 100644
--- a/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilterTest.java
+++ b/shib-networking-spring/src/test/java/net/shibboleth/shared/spring/servlet/impl/SameSiteCookieHeaderFilterTest.java
@@ -29,6 +29,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
+
 import org.springframework.mock.web.MockCookie;
 import org.springframework.mock.web.MockFilterChain;
 import org.springframework.mock.web.MockHttpServletRequest;
@@ -377,11 +379,11 @@ public class SameSiteCookieHeaderFilterTest {
      * @param expectedSize the expected size of the map.
      * @param filter the filter with the field to get.
      */
-    private void testSameSiteMapSize(String fieldName, int expectedSize, Filter filter) {
+    private void testSameSiteMapSize(@Nonnull String fieldName, int expectedSize, @Nonnull Filter filter) {
         
         Object sameSiteSet = ReflectionTestUtils.getField(filter, fieldName);
-        Assert.assertNotNull(sameSiteSet);
         Assert.assertTrue(sameSiteSet instanceof Map);
+        assert(sameSiteSet != null);
         Assert.assertEquals(((Map<?,?>)sameSiteSet).size(),expectedSize);
     }
     
@@ -416,7 +418,8 @@ public class SameSiteCookieHeaderFilterTest {
             Assert.assertNotNull(cookie);
             Assert.assertTrue(cookie instanceof MockCookie);
             MockCookie mockCookie = (MockCookie)cookie;
-                      
+
+            assert(mockCookie != null);
             if (cookiesWithSamesite.contains(mockCookie.getName())) {
                 Assert.assertNotNull(mockCookie.getSameSite());
                 Assert.assertEquals(mockCookie.getSameSite(),sameSiteValue);                           
diff --git a/shib-networking/src/main/java/net/shibboleth/shared/httpclient/ContextHandlingHttpClient.java b/shib-networking/src/main/java/net/shibboleth/shared/httpclient/ContextHandlingHttpClient.java
index 8b5438d3..d701f077 100644
--- a/shib-networking/src/main/java/net/shibboleth/shared/httpclient/ContextHandlingHttpClient.java
+++ b/shib-networking/src/main/java/net/shibboleth/shared/httpclient/ContextHandlingHttpClient.java
@@ -146,33 +146,34 @@ class ContextHandlingHttpClient extends CloseableHttpClient {
      * @param context the HTTP context
      * @throws IOException if any handler throws an error
      */
-    private void invokeBefore(final HttpUriRequest request, final HttpClientContext context) throws IOException {
+    private void invokeBefore(@Nonnull final HttpUriRequest request, @Nonnull final HttpClientContext context)
+            throws IOException {
         log.trace("In invokeBefore");
         
         final List<Throwable> errors = new LazyList<>();
 
         for (final HttpClientContextHandler handler : handlers) {
-            try {
-                if (handler != null) {
+            if (handler != null) {
+                try {
                     log.trace("Invoking static handler invokeBefore: {}", handler.getClass().getName());
                     handler.invokeBefore(context, request);
+                } catch (final Throwable t) {
+                    log.warn("Static handler invokeBefore threw: {}", handler.getClass().getName(), t);
+                    errors.add(t);
                 }
-            } catch (final Throwable t) {
-                log.warn("Static handler invokeBefore threw: {}", handler.getClass().getName(), t);
-                errors.add(t);
             }
         }
 
         for (final HttpClientContextHandler handler 
                 : HttpClientSupport.getDynamicContextHandlerList(context)) {
-            try {
-                if (handler != null) {
+            if (handler != null) {
+                try {
                     log.trace("Invoking dynamic handler invokeBefore: {}", handler.getClass().getName());
                     handler.invokeBefore(context, request);
+                } catch (final Throwable t) {
+                    log.warn("Dynamic handler invokeBefore threw: {}", handler.getClass().getName(), t);
+                    errors.add(t);
                 }
-            } catch (final Throwable t) {
-                log.warn("Dynamic handler invokeBefore threw: {}", handler.getClass().getName(), t);
-                errors.add(t);
             }
         }
         
@@ -196,7 +197,7 @@ class ContextHandlingHttpClient extends CloseableHttpClient {
      *                     is a type of unchecked error (RuntimeException or Error) that will be propagated out
      *                     here as well.
      */
-    private void invokeAfter(final HttpUriRequest request, final HttpClientContext context, 
+    private void invokeAfter(@Nonnull final HttpUriRequest request, @Nonnull final HttpClientContext context, 
             final Throwable priorError) throws IOException {
         log.trace("In invokeAfter");
         
@@ -204,26 +205,26 @@ class ContextHandlingHttpClient extends CloseableHttpClient {
             
         for (final HttpClientContextHandler handler 
                 : Lists.reverse(HttpClientSupport.getDynamicContextHandlerList(context))) {
-            try {
-                if (handler != null) {
+            if (handler != null) {
+                try {
                     log.trace("Invoking dynamic handler invokeAfter: {}", handler.getClass().getName());
                     handler.invokeAfter(context, request);
+                } catch (final Throwable t) {
+                    log.warn("Dynamic handler invokeAfter threw: {}", handler.getClass().getName(), t);
+                    errors.add(t);
                 }
-            } catch (final Throwable t) {
-                log.warn("Dynamic handler invokeAfter threw: {}", handler.getClass().getName(), t);
-                errors.add(t);
             }
         }
 
         for (final HttpClientContextHandler handler : Lists.reverse(handlers)) {
-            try {
-                if (handler != null) {
+            if (handler != null) {
+                try {
                     log.trace("Invoking static handler invokeAfter: {}", handler.getClass().getName());
                     handler.invokeAfter(context, request);
+                } catch (final Throwable t) {
+                    log.warn("Static handler invokeAfter threw: {}", handler.getClass().getName(), t);
+                    errors.add(t);
                 }
-            } catch (final Throwable t) {
-                log.warn("Static handler invokeAfter threw: {}", handler.getClass().getName(), t);
-                errors.add(t);
             }
         }
         
diff --git a/shib-networking/src/main/java/net/shibboleth/shared/httpclient/HttpClientBuilder.java b/shib-networking/src/main/java/net/shibboleth/shared/httpclient/HttpClientBuilder.java
index a98a1bbe..3e152a46 100644
--- a/shib-networking/src/main/java/net/shibboleth/shared/httpclient/HttpClientBuilder.java
+++ b/shib-networking/src/main/java/net/shibboleth/shared/httpclient/HttpClientBuilder.java
@@ -260,11 +260,38 @@ public class HttpClientBuilder {
      */
     public HttpClientBuilder(@Nonnull final org.apache.http.impl.client.HttpClientBuilder builder) {
         apacheBuilder = Constraint.isNotNull(builder, "Apache HttpClientBuilder may not be null");
-        resetDefaults();
+        
+        // Defaults are duplicated to avoid static null analyzer issues.
+        maxConnectionsTotal = -1;
+        maxConnectionsPerRoute = -1;
+        socketLocalAddress = null;
+        socketBufferSize = 8192;
+        socketTimeout = Duration.ofSeconds(60);
+        connectionTimeout = Duration.ofSeconds(60);
+        connectionRequestTimeout = Duration.ofSeconds(60);
+        connectionDisregardTLSCertificate = false;
+        connectionCloseAfterResponse = true;
+        connectionStaleCheck = false;
+        connectionProxyHost = null;
+        connectionProxyPort = 8080;
+        connectionProxyUsername = null;
+        connectionProxyPassword = null;
+        httpFollowRedirects = true;
+        httpContentCharSet = "UTF-8";
+        userAgent = null;
+        
+        requestInterceptorsFirst = Collections.emptyList();
+        requestInterceptorsLast = Collections.emptyList();
+        responseInterceptorsFirst = Collections.emptyList();
+        responseInterceptorsLast = Collections.emptyList();
+        staticContextHandlers = Collections.emptyList();
     }
 
     /** Resets all builder parameters to their defaults. */
     public void resetDefaults() {
+        
+        // If changed, change constructor above.
+        
         maxConnectionsTotal = -1;
         maxConnectionsPerRoute = -1;
         socketLocalAddress = null;
diff --git a/shib-networking/src/main/java/net/shibboleth/shared/net/SimpleURLCanonicalizer.java b/shib-networking/src/main/java/net/shibboleth/shared/net/SimpleURLCanonicalizer.java
index 692c7291..1f970b0b 100644
--- a/shib-networking/src/main/java/net/shibboleth/shared/net/SimpleURLCanonicalizer.java
+++ b/shib-networking/src/main/java/net/shibboleth/shared/net/SimpleURLCanonicalizer.java
@@ -106,20 +106,20 @@ public final class SimpleURLCanonicalizer {
     private static void canonicalize(@Nonnull final URLBuilder url) {
         
         // Lower case the scheme.
-        if (url.getScheme() != null) {
-            url.setScheme(url.getScheme().toLowerCase());
-        }
-        
-        final String scheme = url.getScheme();
+        String scheme = url.getScheme();
         if (scheme != null) {
+            scheme = scheme.toLowerCase();
+            url.setScheme(scheme);
+            
             final Integer port = getRegisteredPort(scheme);
             if (port != null && port.equals(url.getPort())) {
                 url.setPort(null);
             }
         }
         
-        if (url.getHost() != null) {
-            url.setHost(url.getHost().toLowerCase());
+        final String host = url.getHost();
+        if (host != null) {
+            url.setHost(host.toLowerCase());
         }
     }
     
diff --git a/shib-networking/src/main/java/net/shibboleth/shared/net/URLBuilder.java b/shib-networking/src/main/java/net/shibboleth/shared/net/URLBuilder.java
index 20957cf0..55b6c655 100644
--- a/shib-networking/src/main/java/net/shibboleth/shared/net/URLBuilder.java
+++ b/shib-networking/src/main/java/net/shibboleth/shared/net/URLBuilder.java
@@ -304,7 +304,7 @@ public class URLBuilder {
         }
 
         if (!Strings.isNullOrEmpty(path)) {
-            if (!path.startsWith("/")) {
+            if (path != null && !path.startsWith("/")) {
                 builder.append("/");
             }
             builder.append(path);
diff --git a/shib-networking/src/main/java/net/shibboleth/shared/servlet/impl/StubbedFilter.java b/shib-networking/src/main/java/net/shibboleth/shared/servlet/impl/StubbedFilter.java
index 2fc5bae6..d58c3f1f 100644
--- a/shib-networking/src/main/java/net/shibboleth/shared/servlet/impl/StubbedFilter.java
+++ b/shib-networking/src/main/java/net/shibboleth/shared/servlet/impl/StubbedFilter.java
@@ -19,6 +19,7 @@ package net.shibboleth.shared.servlet.impl;
 
 import java.io.IOException;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import jakarta.servlet.Filter;
@@ -39,7 +40,7 @@ import net.shibboleth.shared.primitive.StringSupport;
 public class StubbedFilter implements Filter {
     
     /** Class name to warn about, defaults to the name of this class (or its superclass). */
-    @Nullable @NotEmpty String className;
+    @Nonnull @NotEmpty final String className;
     
     /** Constructor. */
     public StubbedFilter() {
@@ -52,10 +53,11 @@ public class StubbedFilter implements Filter {
      * @param name overrides class name for warning messages
      */
     public StubbedFilter(@Nullable @NotEmpty @ParameterName(name="name") final String name) {
-        className = StringSupport.trimOrNull(name);
-        if (className == null) {
-            className = "Servlet Filter " + getClass().getName();
+        String s = StringSupport.trimOrNull(name);
+        if (s == null) {
+            s = "Servlet Filter " + getClass().getName();
         }
+        className = s;
     }
     
     /** {@inheritDoc} */
diff --git a/shib-networking/src/test/java/net/shibboleth/shared/net/CookieManagerTest.java b/shib-networking/src/test/java/net/shibboleth/shared/net/CookieManagerTest.java
index 2641a6de..2002cd51 100644
--- a/shib-networking/src/test/java/net/shibboleth/shared/net/CookieManagerTest.java
+++ b/shib-networking/src/test/java/net/shibboleth/shared/net/CookieManagerTest.java
@@ -30,6 +30,7 @@ import jakarta.servlet.http.HttpServletResponse;
 import net.shibboleth.shared.component.ComponentInitializationException;
 
 /** {@link CookieManager} unit test. */
+ at SuppressWarnings("javadoc")
 public class CookieManagerTest {
 
     @Test public void testInitFailure() {
@@ -65,7 +66,7 @@ public class CookieManagerTest {
         cm.addCookie("foo", "bar");
 
         Cookie cookie = response.getCookie("foo");
-        Assert.assertNotNull(cookie);
+        assert(cookie != null);
         Assert.assertEquals(cookie.getValue(), "bar");
         Assert.assertEquals(cookie.getPath(), "/idp");
         Assert.assertNull(cookie.getDomain());
@@ -86,7 +87,7 @@ public class CookieManagerTest {
         cm.addCookie("foo", "bar");
         
         Cookie cookie = response.getCookie("foo");
-        Assert.assertNotNull(cookie);
+        assert(cookie != null);
         Assert.assertEquals(cookie.getValue(), "bar");
         Assert.assertEquals(cookie.getPath(), "/idp");
         Assert.assertNull(cookie.getDomain());
@@ -108,7 +109,7 @@ public class CookieManagerTest {
         cm.unsetCookie("foo");
         
         Cookie cookie = response.getCookie("foo");
-        Assert.assertNotNull(cookie);
+        assert(cookie != null);
         Assert.assertNull(cookie.getValue());
         Assert.assertEquals(cookie.getPath(), "/idp");
         Assert.assertNull(cookie.getDomain());
diff --git a/shib-networking/src/test/java/net/shibboleth/shared/net/IPRangeTest.java b/shib-networking/src/test/java/net/shibboleth/shared/net/IPRangeTest.java
index f59e53c8..a314941c 100644
--- a/shib-networking/src/test/java/net/shibboleth/shared/net/IPRangeTest.java
+++ b/shib-networking/src/test/java/net/shibboleth/shared/net/IPRangeTest.java
@@ -23,6 +23,7 @@ import java.net.InetAddress;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+ at SuppressWarnings("javadoc")
 public class IPRangeTest {
     
     @Test public void testValidV4Addresses() {
@@ -117,22 +118,30 @@ public class IPRangeTest {
                 {(byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x90, (byte) 0xab, (byte) 0xcd,
                         (byte) 0xef, (byte) 0xff, (byte) 0xff, (byte) 0xaa, (byte) 0xaa, (byte) 0xbb, (byte) 0xbb,
                         (byte) 0xcc, (byte) 0xcc,};
-        Assert.assertEquals(v6a.getNetworkAddress().getAddress(), expected6a);
+        InetAddress address = v6a.getNetworkAddress();
+        assert(address != null);
+        Assert.assertEquals(address.getAddress(), expected6a);
 
         IPRange v6b = IPRange.parseCIDRBlock("1234:5678:90ab:cdef:FfFf:AaAa:BBBB:CCCC/104");
         byte[] expected6b =
                 {(byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x90, (byte) 0xab, (byte) 0xcd,
                         (byte) 0xef, (byte) 0xff, (byte) 0xff, (byte) 0xaa, (byte) 0xaa, (byte) 0xbb, (byte) 0x00,
                         (byte) 0x00, (byte) 0x00,};
-        Assert.assertEquals(v6b.getNetworkAddress().getAddress(), expected6b);
+        address = v6b.getNetworkAddress();
+        assert(address != null);
+        Assert.assertEquals(address.getAddress(), expected6b);
 
         IPRange v4a = IPRange.parseCIDRBlock("192.168.117.17/32");
         byte[] expected4a = {(byte) 192, (byte) 168, (byte) 117, (byte) 17};
-        Assert.assertEquals(v4a.getNetworkAddress().getAddress(), expected4a);
+        address = v4a.getNetworkAddress();
+        assert(address != null);
+        Assert.assertEquals(address.getAddress(), expected4a);
 
         IPRange v4b = IPRange.parseCIDRBlock("192.168.117.17/16");
         byte[] expected4b = {(byte) 192, (byte) 168, (byte) 0, (byte) 0};
-        Assert.assertEquals(v4b.getNetworkAddress().getAddress(), expected4b);
+        address = v4b.getNetworkAddress();
+        assert(address != null);
+        Assert.assertEquals(address.getAddress(), expected4b);
     }
 
     @Test public void testGetHostAddress() {
@@ -143,8 +152,10 @@ public class IPRangeTest {
         Assert.assertNull(v6b.getHostAddress());
 
         IPRange v6c = IPRange.parseCIDRBlock("1234:5678:90ab:cdef:FfFf:AaAa:BBBB:CCCC/64");
-        Assert.assertNotNull(v6c.getHostAddress());
-        Assert.assertEquals(v6c.getHostAddress().getAddress(), v6a.getNetworkAddress().getAddress());
+        InetAddress address1 = v6c.getHostAddress();
+        InetAddress address2 = v6a.getNetworkAddress();
+        assert(address1 != null && address2 != null);
+        Assert.assertEquals(address1.getAddress(), address2.getAddress());
 
         IPRange v4a = IPRange.parseCIDRBlock("192.168.117.17/32");
         Assert.assertNull(v4a.getHostAddress());
@@ -153,8 +164,10 @@ public class IPRangeTest {
         Assert.assertNull(v4b.getHostAddress());
 
         IPRange v4c = IPRange.parseCIDRBlock("192.168.117.17/16");
-        Assert.assertNotNull(v4c.getHostAddress());
-        Assert.assertEquals(v4c.getHostAddress().getAddress(), v4a.getNetworkAddress().getAddress());
+        address1 = v4c.getHostAddress();
+        address2 = v4a.getNetworkAddress();
+        assert(address1 != null && address2 != null);
+        Assert.assertEquals(address1.getAddress(), address2.getAddress());
     }
     
     private void testInvalid(final String address) {

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


More information about the commits mailing list