From bbd3b2060c8911e4e592956c205af80554ff45a2 Mon Sep 17 00:00:00 2001 From: Emanuel Alves Date: Thu, 14 Sep 2023 15:12:14 +0100 Subject: [PATCH] Fix spotbugs errors Signed-off-by: Emanuel Alves --- .../dapr/it/state/AbstractStateClientIT.java | 26 ++++--- .../domain/BulkSubscribeAppResponse.java | 4 +- .../client/domain/GetBulkStateRequest.java | 2 +- .../domain/GetConfigurationRequest.java | 2 +- .../client/domain/PublishEventRequest.java | 2 +- .../java/io/dapr/client/domain/State.java | 3 +- .../domain/SubscribeConfigurationRequest.java | 2 +- spotbugs-exclude.xml | 70 +++++++++++++++++++ 8 files changed, 93 insertions(+), 18 deletions(-) diff --git a/sdk-tests/src/test/java/io/dapr/it/state/AbstractStateClientIT.java b/sdk-tests/src/test/java/io/dapr/it/state/AbstractStateClientIT.java index 4c3cbeb20..88e99fd48 100644 --- a/sdk-tests/src/test/java/io/dapr/it/state/AbstractStateClientIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/state/AbstractStateClientIT.java @@ -245,8 +245,8 @@ public void saveUpdateAndGetState() { //review that the update was success action assertNotNull(myDataResponse, "expected non null response"); - assertEquals(myDataResponse.getValue().getPropertyA(), "data in property A"); - assertEquals(myDataResponse.getValue().getPropertyB(), "data in property B2"); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); } @Test @@ -402,7 +402,7 @@ public void saveUpdateAndGetStateWithWrongEtag() { data.setPropertyA("data in property A"); data.setPropertyB("data in property B"); - //Create deferred action to save the sate + //Create deferred action to save the state Mono saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null); //execute the save state action saveResponse.block(); @@ -427,8 +427,9 @@ public void saveUpdateAndGetStateWithWrongEtag() { data.setPropertyB("data in property B2"); //Create deferred action to update the data using the incorrect etag saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, "99999999999999", data, null); - saveResponse.block(); + Mono finalSaveResponse = saveResponse; + assertThrows(RuntimeException.class, finalSaveResponse::block); response = daprClient.getState(STATE_STORE_NAME, new State<>(stateKey, (MyData) null, null), MyData.class); //retrive the data wihout any etag @@ -514,10 +515,11 @@ public void saveAndDeleteStateWithWrongEtag() { //Create deferred action to delete an state sending the incorrect etag Mono deleteResponse = daprClient.deleteState(STATE_STORE_NAME, stateKey, "99999999999", null); //execute the delete of the state, this should throw an exception - deleteResponse.block(); - //Create deferred action to get the sate without an etag - response = daprClient.getState(STATE_STORE_NAME, new State(stateKey), MyData.class); + assertThrows(RuntimeException.class, deleteResponse::block); + + //Create deferred action to get the state without an etag + response = daprClient.getState(STATE_STORE_NAME, new State<>(stateKey), MyData.class); myDataResponse = response.block(); //Review that the response is null, because the state was deleted @@ -545,7 +547,7 @@ public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() { saveResponse.block(); - //crate deferred action to retrieve the state + //create deferred action to retrieve the state Mono> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class); //execute the retrieve of the state using options @@ -557,7 +559,7 @@ public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() { assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); - //change data to be udpated + //change data to be updated data.setPropertyA("data in property A2"); data.setPropertyB("data in property B2"); //create deferred action to update the action with options @@ -570,8 +572,10 @@ public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() { data.setPropertyB("data in property B2"); //create deferred action to update the action with the same etag saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, myDataResponse.getEtag(), data, stateOptions); - //throws an exception, the state was already udpated - saveResponse.block(); + //throws an exception, the state was already updated + + Mono finalSaveResponse2 = saveResponse; + assertThrows(RuntimeException.class, () -> finalSaveResponse2.block()); response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class); State myLastDataResponse = response.block(); diff --git a/sdk/src/main/java/io/dapr/client/domain/BulkSubscribeAppResponse.java b/sdk/src/main/java/io/dapr/client/domain/BulkSubscribeAppResponse.java index 5043aa070..511e3468f 100644 --- a/sdk/src/main/java/io/dapr/client/domain/BulkSubscribeAppResponse.java +++ b/sdk/src/main/java/io/dapr/client/domain/BulkSubscribeAppResponse.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -32,8 +33,7 @@ public final class BulkSubscribeAppResponse { @JsonCreator public BulkSubscribeAppResponse( @JsonProperty("statuses") List statuses) { - this.statuses = new ArrayList<>(); - this.statuses.addAll(statuses); + this.statuses = Collections.unmodifiableList(statuses); } public List getStatuses() { diff --git a/sdk/src/main/java/io/dapr/client/domain/GetBulkStateRequest.java b/sdk/src/main/java/io/dapr/client/domain/GetBulkStateRequest.java index 47a20e2e0..2f5270879 100644 --- a/sdk/src/main/java/io/dapr/client/domain/GetBulkStateRequest.java +++ b/sdk/src/main/java/io/dapr/client/domain/GetBulkStateRequest.java @@ -27,7 +27,7 @@ public class GetBulkStateRequest { private final List keys; - private Map metadata; + private Map metadata = Collections.emptyMap(); private int parallelism = 1; diff --git a/sdk/src/main/java/io/dapr/client/domain/GetConfigurationRequest.java b/sdk/src/main/java/io/dapr/client/domain/GetConfigurationRequest.java index a8de2bd61..78235230c 100644 --- a/sdk/src/main/java/io/dapr/client/domain/GetConfigurationRequest.java +++ b/sdk/src/main/java/io/dapr/client/domain/GetConfigurationRequest.java @@ -33,7 +33,7 @@ public class GetConfigurationRequest { */ public GetConfigurationRequest(String storeName, List keys) { this.storeName = storeName; - this.keys = keys == null ? Collections.EMPTY_LIST : Collections.unmodifiableList(keys); + this.keys = keys == null ? Collections.emptyList() : Collections.unmodifiableList(keys); } public GetConfigurationRequest setMetadata(Map metadata) { diff --git a/sdk/src/main/java/io/dapr/client/domain/PublishEventRequest.java b/sdk/src/main/java/io/dapr/client/domain/PublishEventRequest.java index fbb58bdbf..a2e65955a 100644 --- a/sdk/src/main/java/io/dapr/client/domain/PublishEventRequest.java +++ b/sdk/src/main/java/io/dapr/client/domain/PublishEventRequest.java @@ -30,7 +30,7 @@ public class PublishEventRequest { private String contentType; - private Map metadata = new HashMap<>(); + private Map metadata = Collections.emptyMap(); /** * Constructor for PublishEventRequest. diff --git a/sdk/src/main/java/io/dapr/client/domain/State.java b/sdk/src/main/java/io/dapr/client/domain/State.java index 3ec521773..ae087d986 100644 --- a/sdk/src/main/java/io/dapr/client/domain/State.java +++ b/sdk/src/main/java/io/dapr/client/domain/State.java @@ -13,6 +13,7 @@ package io.dapr.client.domain; +import java.util.Collections; import java.util.Map; /** @@ -116,7 +117,7 @@ public State(String key, T value, String etag, Map metadata, Sta this.value = value; this.key = key; this.etag = etag; - this.metadata = metadata; + this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata); this.options = options; this.error = null; } diff --git a/sdk/src/main/java/io/dapr/client/domain/SubscribeConfigurationRequest.java b/sdk/src/main/java/io/dapr/client/domain/SubscribeConfigurationRequest.java index 25118c400..9b7e5545b 100644 --- a/sdk/src/main/java/io/dapr/client/domain/SubscribeConfigurationRequest.java +++ b/sdk/src/main/java/io/dapr/client/domain/SubscribeConfigurationRequest.java @@ -33,7 +33,7 @@ public class SubscribeConfigurationRequest { */ public SubscribeConfigurationRequest(String storeName, List keys) { this.storeName = storeName; - this.keys = keys == null ? Collections.EMPTY_LIST : Collections.unmodifiableList(keys); + this.keys = keys == null ? Collections.emptyList() : Collections.unmodifiableList(keys); } public SubscribeConfigurationRequest setMetadata(Map metadata) { diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index e68bf4cad..dcbe9585b 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -3,4 +3,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file