From 0b24401def6e3e68e3eff1f748fd61f7144c8580 Mon Sep 17 00:00:00 2001 From: Brendan Le Ny Date: Fri, 21 Jun 2024 10:45:08 +0200 Subject: [PATCH] Fix NPE when defining retry name for creation --- .../sh/libre/scim/core/AbstractScimService.java | 2 +- src/main/java/sh/libre/scim/core/ScimClient.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/sh/libre/scim/core/AbstractScimService.java b/src/main/java/sh/libre/scim/core/AbstractScimService.java index e32f178977..53a6738b35 100644 --- a/src/main/java/sh/libre/scim/core/AbstractScimService.java +++ b/src/main/java/sh/libre/scim/core/AbstractScimService.java @@ -45,7 +45,7 @@ public abstract class AbstractScimService implements AutoCloseable { return new ScimClient(scimRequestBuilder, scimResourceType); } - public EntityOnRemoteScimId create(ResourceNode scimForCreation) { - Retry retry = retryRegistry.retry("create-" + scimForCreation.getId().get()); + public EntityOnRemoteScimId create(KeycloakId id, ResourceNode scimForCreation) { + if (scimForCreation.getId().isPresent()) { + throw new IllegalArgumentException( + "%s is already created on remote with id %s".formatted(id, scimForCreation.getId().get()) + ); + } + Retry retry = retryRegistry.retry("create-%s".formatted(id.asString())); ServerResponse response = retry.executeSupplier(() -> { try { return scimRequestBuilder @@ -98,7 +103,7 @@ public class ScimClient implements AutoCloseable { } public void replace(EntityOnRemoteScimId externalId, ResourceNode scimForReplace) { - Retry retry = retryRegistry.retry("replace-" + scimForReplace.getId().get()); + Retry retry = retryRegistry.retry("replace-%s".formatted(externalId.asString())); ServerResponse response = retry.executeSupplier(() -> { try { return scimRequestBuilder @@ -113,7 +118,7 @@ public class ScimClient implements AutoCloseable { } public void delete(EntityOnRemoteScimId externalId) { - Retry retry = retryRegistry.retry("delete-" + externalId.asString()); + Retry retry = retryRegistry.retry("delete-%s".formatted(externalId.asString())); ServerResponse response = retry.executeSupplier(() -> { try { return scimRequestBuilder.delete(getResourceClass(), getScimEndpoint(), externalId.asString())