[java-opensaml] branch main updated: IDP-2083 - Treat NonnullElements as the default for collections

Scott Cantor cantor.2 at osu.edu
Mon Jun 5 16:24:56 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=c26079c34d82dcd7007cbc1e55ee3cd3981cbfc5

The following commit(s) were added to refs/heads/main by this push:
     new c26079c34 IDP-2083 - Treat NonnullElements as the default for collections
c26079c34 is described below

commit c26079c34d82dcd7007cbc1e55ee3cd3981cbfc5
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Jun 5 12:24:53 2023 -0400

    IDP-2083 - Treat NonnullElements as the default for collections
    
    https://shibboleth.atlassian.net/browse/IDP-2083
    
    Review opensaml-storage-api/impl.
---
 .../storage/AbstractMapBackedStorageService.java   | 17 ++++++++---------
 .../opensaml/storage/annotation/package-info.java  |  5 ++++-
 .../java/org/opensaml/storage/package-info.java    |  5 ++++-
 .../storage/impl/MemoryStorageService.java         | 12 ++++++++----
 .../client/AbstractClientStorageServiceStore.java  |  5 ++---
 .../impl/client/ClientStorageLoadContext.java      |  5 ++---
 .../impl/client/ClientStorageSaveContext.java      |  5 ++---
 .../storage/impl/client/ClientStorageService.java  |  5 ++---
 .../impl/client/LoadClientStorageServices.java     | 21 ++++++++++-----------
 .../client/PopulateClientStorageLoadContext.java   | 14 ++++++++------
 .../client/PopulateClientStorageSaveContext.java   | 11 +++++++----
 .../SaveCookieBackedClientStorageServices.java     | 22 +++++++++++-----------
 .../impl/client/XMLClientStorageServiceStore.java  |  4 ++--
 .../opensaml/storage/impl/client/package-info.java |  5 ++++-
 .../storage/impl/memcached/package-info.java       |  5 ++++-
 .../org/opensaml/storage/impl/package-info.java    |  5 ++++-
 16 files changed, 82 insertions(+), 64 deletions(-)

diff --git a/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java b/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java
index 2f30265fa..1dccf97c0 100644
--- a/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java
+++ b/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java
@@ -29,7 +29,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import net.shibboleth.shared.annotation.constraint.Live;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.Positive;
 import net.shibboleth.shared.collection.Pair;
@@ -267,8 +266,8 @@ public abstract class AbstractMapBackedStorageService extends AbstractStorageSer
      * 
      * @throws IOException to signal errors
      */
-    @Nonnull @NonnullElements @Live
-    protected abstract Map<String, Map<String, MutableStorageRecord<?>>> getContextMap() throws IOException;
+    @Nonnull @Live protected abstract Map<String, Map<String, MutableStorageRecord<?>>> getContextMap()
+            throws IOException;
 
     /**
      * A callback to indicate that data has been modified.
@@ -471,14 +470,14 @@ public abstract class AbstractMapBackedStorageService extends AbstractStorageSer
      * 
      * @return  true iff anything was purged
      */
-    protected boolean reapWithLock(@Nonnull @NonnullElements final Map<String, MutableStorageRecord<?>> dataMap,
-            final long expiration) {
-        
+    protected boolean reapWithLock(@Nonnull final Map<String, MutableStorageRecord<?>> dataMap, final long expiration) {
         return dataMap.entrySet().removeIf(new Predicate<Entry<String, MutableStorageRecord<?>>>() {
                 public boolean test(@Nullable final Entry<String, MutableStorageRecord<?>> entry) {
-                    assert entry != null;
-                    final Long exp = entry.getValue().getExpiration();
-                    return exp != null && exp <= expiration;
+                    if (entry != null) {
+                        final Long exp = entry.getValue().getExpiration();
+                        return exp != null && exp <= expiration;
+                    }
+                    return false;
                 }
             }
         );
diff --git a/opensaml-storage-api/src/main/java/org/opensaml/storage/annotation/package-info.java b/opensaml-storage-api/src/main/java/org/opensaml/storage/annotation/package-info.java
index b88e886fe..5c581fa70 100644
--- a/opensaml-storage-api/src/main/java/org/opensaml/storage/annotation/package-info.java
+++ b/opensaml-storage-api/src/main/java/org/opensaml/storage/annotation/package-info.java
@@ -16,4 +16,7 @@
  */
 
 /** Annotations in support of {@link org.opensaml.storage.StorageService} use by custom objects. */
-package org.opensaml.storage.annotation;
\ No newline at end of file
+ at NonnullElements
+package org.opensaml.storage.annotation;
+
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
diff --git a/opensaml-storage-api/src/main/java/org/opensaml/storage/package-info.java b/opensaml-storage-api/src/main/java/org/opensaml/storage/package-info.java
index d1bf509af..00c288315 100644
--- a/opensaml-storage-api/src/main/java/org/opensaml/storage/package-info.java
+++ b/opensaml-storage-api/src/main/java/org/opensaml/storage/package-info.java
@@ -19,4 +19,7 @@
  * Interfaces and classes for storing state data of the type used in replay caches, conversation identifiers, etc.
  * Through these interfaces such data may be stored in memory, to a database, or replicated across cluster nodes.
  */
-package org.opensaml.storage;
\ No newline at end of file
+ at NonnullElements
+package org.opensaml.storage;
+
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java
index d3be446b4..776ed1f4b 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/MemoryStorageService.java
@@ -31,7 +31,6 @@ import javax.annotation.Nullable;
 
 import net.shibboleth.shared.annotation.constraint.Live;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
@@ -50,7 +49,7 @@ public class MemoryStorageService extends AbstractMapBackedStorageService implem
     @Nonnull private final Logger log = LoggerFactory.getLogger(MemoryStorageService.class);
 
     /** Map of contexts. */
-    @NonnullAfterInit @NonnullElements private Map<String, Map<String, MutableStorageRecord<?>>> contextMap;
+    @NonnullAfterInit private Map<String, Map<String, MutableStorageRecord<?>>> contextMap;
     
     /** A shared lock to synchronize access. */
     @NonnullAfterInit private ReadWriteLock lock;
@@ -84,13 +83,17 @@ public class MemoryStorageService extends AbstractMapBackedStorageService implem
 
     /** {@inheritDoc} */
     @Override
-    @Nonnull @NonnullElements @Live protected Map<String, Map<String, MutableStorageRecord<?>>> getContextMap() {
+    @Nonnull @Live protected Map<String, Map<String, MutableStorageRecord<?>>> getContextMap() {
+        checkComponentActive();
+        assert contextMap != null;
         return contextMap;
     }
 
     /** {@inheritDoc} */
     @Override
     @Nonnull protected ReadWriteLock getLock() {
+        checkComponentActive();
+        assert lock != null;
         return lock;
     }
     
@@ -115,7 +118,8 @@ public class MemoryStorageService extends AbstractMapBackedStorageService implem
                     final Collection<Map<String, MutableStorageRecord<?>>> contexts = getContextMap().values();
                     final Iterator<Map<String, MutableStorageRecord<?>>> i = contexts.iterator();
                     while (i.hasNext()) {
-                        final Map<String, MutableStorageRecord<?>> context = i.next(); 
+                        final Map<String, MutableStorageRecord<?>> context = i.next();
+                        assert context != null;
                         if (reapWithLock(context, now)) {
                             purged = true;
                             if (context.isEmpty()) {
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/AbstractClientStorageServiceStore.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/AbstractClientStorageServiceStore.java
index 1b34fe4bb..05a73b5cf 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/AbstractClientStorageServiceStore.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/AbstractClientStorageServiceStore.java
@@ -28,7 +28,6 @@ import org.opensaml.storage.MutableStorageRecord;
 import org.opensaml.storage.impl.client.ClientStorageService.ClientStorageSource;
 
 import net.shibboleth.shared.annotation.constraint.Live;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.logic.Constraint;
 
@@ -40,7 +39,7 @@ import net.shibboleth.shared.logic.Constraint;
 public abstract class AbstractClientStorageServiceStore implements ClientStorageServiceStore {
 
     /** The underlying map of data records. */
-    @Nonnull @NonnullElements private final Map<String, Map<String, MutableStorageRecord<?>>> contextMap;
+    @Nonnull private final Map<String, Map<String, MutableStorageRecord<?>>> contextMap;
     
     /** Data source. */
     @Nullable private ClientStorageSource source;
@@ -75,7 +74,7 @@ public abstract class AbstractClientStorageServiceStore implements ClientStorage
     }
 
     /** {@inheritDoc} */
-    @Nonnull @NonnullElements @Live public Map<String,Map<String,MutableStorageRecord<?>>> getContextMap() {
+    @Nonnull @Live public Map<String,Map<String,MutableStorageRecord<?>>> getContextMap() {
         return contextMap;
     }
     
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageLoadContext.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageLoadContext.java
index 8b7b93c79..63883694a 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageLoadContext.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageLoadContext.java
@@ -25,7 +25,6 @@ import javax.annotation.Nonnull;
 import org.opensaml.messaging.context.BaseContext;
 
 import net.shibboleth.shared.annotation.constraint.Live;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 
 /**
  * A subcontext for driving the loading of data from a client into one or more
@@ -34,7 +33,7 @@ import net.shibboleth.shared.annotation.constraint.NonnullElements;
 public class ClientStorageLoadContext extends BaseContext {
 
     /** The collection of storage keys to load from the client. */
-    @Nonnull @NonnullElements private Collection<String> storageKeys;
+    @Nonnull private Collection<String> storageKeys;
     
     /** Constructor. */
     public ClientStorageLoadContext() {
@@ -46,7 +45,7 @@ public class ClientStorageLoadContext extends BaseContext {
      * 
      * @return modifiable collection of storage keys to load from the client
      */
-    @Nonnull @NonnullElements @Live public Collection<String> getStorageKeys() {
+    @Nonnull @Live public Collection<String> getStorageKeys() {
         return storageKeys;
     }
 
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageSaveContext.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageSaveContext.java
index c993bc8d0..05380a590 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageSaveContext.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageSaveContext.java
@@ -28,7 +28,6 @@ import org.opensaml.storage.impl.client.ClientStorageService.ClientStorageSource
 import com.google.common.collect.Iterables;
 
 import net.shibboleth.shared.annotation.constraint.Live;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 
 /**
  * A subcontext for driving the saving of data to a client from one or more
@@ -37,7 +36,7 @@ import net.shibboleth.shared.annotation.constraint.NonnullElements;
 public class ClientStorageSaveContext extends BaseContext {
 
     /** Storage operations to perform. */
-    @Nonnull @NonnullElements private Collection<ClientStorageServiceOperation> storageOperations;
+    @Nonnull private Collection<ClientStorageServiceOperation> storageOperations;
     
     /** Constructor. */
     public ClientStorageSaveContext() {
@@ -49,7 +48,7 @@ public class ClientStorageSaveContext extends BaseContext {
      * 
      * @return modifiable collection of storage operations
      */
-    @Nonnull @NonnullElements @Live public Collection<ClientStorageServiceOperation> getStorageOperations() {
+    @Nonnull @Live public Collection<ClientStorageServiceOperation> getStorageOperations() {
         return storageOperations;
     }
     
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageService.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageService.java
index df9f9c219..fac893932 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageService.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/ClientStorageService.java
@@ -47,7 +47,6 @@ import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpSession;
 import net.shibboleth.shared.annotation.constraint.Live;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
@@ -140,7 +139,7 @@ public class ClientStorageService extends AbstractMapBackedStorageService implem
      * 
      * @param map capability map
      */
-    public void setCapabilityMap(@Nonnull @NonnullElements final Map<ClientStorageSource,Integer> map) {
+    public void setCapabilityMap(@Nonnull final Map<ClientStorageSource,Integer> map) {
         checkSetterPreconditions();
         Constraint.isNotNull(map, "Capability map cannot be null");
         
@@ -342,7 +341,7 @@ public class ClientStorageService extends AbstractMapBackedStorageService implem
 
     /** {@inheritDoc} */
     @Override
-    @Nonnull @NonnullElements @Live protected Map<String, Map<String, MutableStorageRecord<?>>> getContextMap()
+    @Nonnull @Live protected Map<String, Map<String, MutableStorageRecord<?>>> getContextMap()
             throws IOException {
         
         try {
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/LoadClientStorageServices.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/LoadClientStorageServices.java
index 4cb03cdc6..3a15cfa07 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/LoadClientStorageServices.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/LoadClientStorageServices.java
@@ -19,9 +19,9 @@ package org.opensaml.storage.impl.client;
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -37,10 +37,8 @@ import com.google.common.base.Strings;
 
 import jakarta.servlet.http.Cookie;
 import jakarta.servlet.http.HttpServletRequest;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.collection.CollectionSupport;
-import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.net.URISupport;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
@@ -72,7 +70,7 @@ public class LoadClientStorageServices extends AbstractProfileAction {
     private boolean useLocalStorage;
     
     /** The storage service instances to load. */
-    @Nonnull @NonnullElements private Map<String,ClientStorageService> storageServices;
+    @Nonnull private Map<String,ClientStorageService> storageServices;
     
     /** Context to drive storage load. */
     @Nullable private ClientStorageLoadContext clientStorageLoadCtx;
@@ -99,15 +97,16 @@ public class LoadClientStorageServices extends AbstractProfileAction {
      * 
      * @param services instances to check for loading
      */
-    public void setStorageServices(@Nonnull @NonnullElements final Collection<ClientStorageService> services) {
+    public void setStorageServices(@Nullable final Collection<ClientStorageService> services) {
         checkSetterPreconditions();
         
-        Constraint.isNotNull(services, "StorageService collection cannot be null");
-        storageServices = new HashMap<>(services.size());
-        for (final ClientStorageService ss : services) {
-            if (ss != null) {
-                storageServices.put(ss.getStorageName(), ss);
-            }
+        if (services != null) {
+            storageServices = services.stream()
+                    .collect(CollectionSupport.nonnullCollector(Collectors.toUnmodifiableMap(
+                            ClientStorageService::getStorageName, ss -> ss)))
+                    .get();
+        } else {
+            storageServices = CollectionSupport.emptyMap();
         }
     }
     
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageLoadContext.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageLoadContext.java
index 3532f5c1d..3431b0f6b 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageLoadContext.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageLoadContext.java
@@ -22,16 +22,15 @@ import java.util.ArrayList;
 import java.util.Collection;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.opensaml.profile.action.AbstractProfileAction;
 import org.opensaml.profile.action.ActionSupport;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.Logger;
 
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.collection.CollectionSupport;
-import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
@@ -53,7 +52,7 @@ public class PopulateClientStorageLoadContext extends AbstractProfileAction {
     @Nonnull private final Logger log = LoggerFactory.getLogger(PopulateClientStorageLoadContext.class);
 
     /** The storage service instances to check for a loading requirement. */
-    @Nonnull @NonnullElements private Collection<ClientStorageService> storageServices;
+    @Nonnull private Collection<ClientStorageService> storageServices;
     
     /** Constructor. */
     public PopulateClientStorageLoadContext() {
@@ -65,11 +64,14 @@ public class PopulateClientStorageLoadContext extends AbstractProfileAction {
      * 
      * @param services instances to check for loading
      */
-    public void setStorageServices(@Nonnull @NonnullElements final Collection<ClientStorageService> services) {
+    public void setStorageServices(@Nullable final Collection<ClientStorageService> services) {
         checkSetterPreconditions();
         
-        storageServices = CollectionSupport.copyToList(
-                Constraint.isNotNull(services, "StorageService collection cannot be null"));
+        if (services != null) {
+            storageServices = CollectionSupport.copyToList(services);
+        } else {
+            storageServices = CollectionSupport.emptyList();
+        }
     }
     
     /** {@inheritDoc} */
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageSaveContext.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageSaveContext.java
index d1a4088e0..7bd7e7c79 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageSaveContext.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/PopulateClientStorageSaveContext.java
@@ -21,6 +21,7 @@ import java.util.Collection;
 import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.opensaml.profile.action.AbstractProfileAction;
 import org.opensaml.profile.action.ActionSupport;
@@ -30,7 +31,6 @@ import org.slf4j.Logger;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.collection.CollectionSupport;
-import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
@@ -64,11 +64,14 @@ public class PopulateClientStorageSaveContext extends AbstractProfileAction {
      * 
      * @param services instances to check for saving
      */
-    public void setStorageServices(@Nonnull @NonnullElements final Collection<ClientStorageService> services) {
+    public void setStorageServices(@Nullable final Collection<ClientStorageService> services) {
         checkSetterPreconditions();
         
-        storageServices = CollectionSupport.copyToList(
-                Constraint.isNotNull(services, "StorageService collection cannot be null"));
+        if (services != null) {
+            storageServices = CollectionSupport.copyToList(services);
+        } else {
+            storageServices = CollectionSupport.emptyList();
+        }
     }
     
     /** {@inheritDoc} */
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/SaveCookieBackedClientStorageServices.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/SaveCookieBackedClientStorageServices.java
index ac99e2839..67c1cd154 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/SaveCookieBackedClientStorageServices.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/SaveCookieBackedClientStorageServices.java
@@ -18,8 +18,8 @@
 package org.opensaml.storage.impl.client;
 
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -34,9 +34,7 @@ import org.slf4j.Logger;
 import com.google.common.escape.Escaper;
 import com.google.common.net.UrlEscapers;
 
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.collection.CollectionSupport;
-import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
@@ -56,7 +54,7 @@ public class SaveCookieBackedClientStorageServices
     @Nonnull private final Logger log = LoggerFactory.getLogger(SaveCookieBackedClientStorageServices.class);
     
     /** The storage service instances to load, keyed by their bean ID. */
-    @Nonnull @NonnullElements private Map<String,ClientStorageService> storageServices;
+    @Nonnull private Map<String,ClientStorageService> storageServices;
     
     /** Context to drive storage save. */
     @Nullable private ClientStorageSaveContext clientStorageSaveCtx;
@@ -65,6 +63,7 @@ public class SaveCookieBackedClientStorageServices
     @Nonnull private Escaper escaper;
     
     /** Constructor. */
+    @SuppressWarnings("null")
     public SaveCookieBackedClientStorageServices() {
         storageServices = CollectionSupport.emptyMap();
         escaper = UrlEscapers.urlFormParameterEscaper();
@@ -75,15 +74,16 @@ public class SaveCookieBackedClientStorageServices
      * 
      * @param services instances to check for loading
      */
-    public void setStorageServices(@Nonnull @NonnullElements final Collection<ClientStorageService> services) {
+    public void setStorageServices(@Nullable final Collection<ClientStorageService> services) {
         checkSetterPreconditions();
         
-        Constraint.isNotNull(services, "StorageService collection cannot be null");
-        storageServices = new HashMap<>(services.size());
-        for (final ClientStorageService ss : services) {
-            if (ss != null) {
-                storageServices.put(ss.ensureId(), ss);
-            }
+        if (services != null) {
+            storageServices = services.stream()
+                    .collect(CollectionSupport.nonnullCollector(Collectors.toUnmodifiableMap(
+                            ClientStorageService::ensureId, ss -> ss)))
+                    .get();
+        } else {
+            storageServices = CollectionSupport.emptyMap();
         }
     }
     
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/XMLClientStorageServiceStore.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/XMLClientStorageServiceStore.java
index 49d59707b..b33846e69 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/XMLClientStorageServiceStore.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/XMLClientStorageServiceStore.java
@@ -173,7 +173,7 @@ public class XMLClientStorageServiceStore extends AbstractClientStorageServiceSt
 
             if (empty) {
                 log.trace("{} Data is empty", storageService.getLogPrefix());
-                return new ClientStorageServiceOperation(storageService.getId(), storageService.getStorageName(), null,
+                return new ClientStorageServiceOperation(storageService.ensureId(), storageService.getStorageName(), null,
                         source);
             }
             
@@ -187,7 +187,7 @@ public class XMLClientStorageServiceStore extends AbstractClientStorageServiceSt
                         exp > 0 ? Instant.ofEpochMilli(exp) : Instant.now().plus(Duration.ofDays(1)));
                 log.trace("{} Size of data after encryption is {}", storageService.getLogPrefix(), wrapped.length());
                 setDirty(false);
-                return new ClientStorageServiceOperation(storageService.getId(), storageService.getStorageName(),
+                return new ClientStorageServiceOperation(storageService.ensureId(), storageService.getStorageName(),
                         wrapped, source);
             } catch (final DataSealerException e) {
                 throw new IOException(e);
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/package-info.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/package-info.java
index 894bb0f7c..c2c5c6fff 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/package-info.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/client/package-info.java
@@ -19,4 +19,7 @@
  * Implementation of {@link org.opensaml.storage.StorageService} that unifies cookie and
  * HTML Local Storage.
  */
-package org.opensaml.storage.impl.client;
\ No newline at end of file
+ at NonnullElements
+package org.opensaml.storage.impl.client;
+
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/memcached/package-info.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/memcached/package-info.java
index 12616e4a9..38fe8f59f 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/memcached/package-info.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/memcached/package-info.java
@@ -18,4 +18,7 @@
 /**
  * Implementation of memcached {@link org.opensaml.storage.StorageService}.
  */
-package org.opensaml.storage.impl.memcached;
\ No newline at end of file
+ at NonnullElements
+package org.opensaml.storage.impl.memcached;
+
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/package-info.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/package-info.java
index a6e1f212b..d7aac05b8 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/package-info.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/package-info.java
@@ -18,4 +18,7 @@
 /**
  * Storage-related implementation classes.
  */
-package org.opensaml.storage.impl;
\ No newline at end of file
+ at NonnullElements
+package org.opensaml.storage.impl;
+
+import net.shibboleth.shared.annotation.constraint.NonnullElements;

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


More information about the commits mailing list