Make UUID factory initialisation more robust
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 10 Dec 2023 17:06:45 +0000 (18:06 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 10 Dec 2023 17:06:45 +0000 (18:06 +0100)
org.argeo.cms/src/org/argeo/cms/acr/CmsUuidFactory.java

index 7270c0896255f4596f73cc489a7819f95f5bf791..357a0102f432f639058ce4deff06c546e5be3625 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Enumeration;
 
 import org.argeo.api.cms.CmsLog;
 import org.argeo.api.uuid.ConcurrentUuidFactory;
+import org.argeo.api.uuid.NodeIdSupplier;
 import org.argeo.api.uuid.UuidBinaryUtils;
 
 public class CmsUuidFactory extends ConcurrentUuidFactory {
@@ -73,8 +74,10 @@ public class CmsUuidFactory extends ConcurrentUuidFactory {
                        }
                }
                InetAddress selectedIp = selectedIpv6 != null ? selectedIpv6 : selectedIpv4;
-               if (selectedIp == null)
-                       throw new IllegalStateException("No IP address found");
+               if (selectedIp == null) {
+                       log.warn("No IP address found, using a random node id for UUID generation");
+                       return NodeIdSupplier.randomNodeId();
+               }
                byte[] digest = sha1(selectedIp.getAddress());
                log.info("Use IP " + selectedIp + " hashed as " + UuidBinaryUtils.toHexString(digest) + " as node id");
                byte[] nodeId = toNodeIdBytes(digest, 0);