Skip to content

Commit

Permalink
Fix spotbugs errors
Browse files Browse the repository at this point in the history
Signed-off-by: Emanuel Alves <[email protected]>
  • Loading branch information
ejba committed Sep 14, 2023
1 parent 1c93ae6 commit bbd3b20
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 18 deletions.
26 changes: 15 additions & 11 deletions sdk-tests/src/test/java/io/dapr/it/state/AbstractStateClientIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Void> saveResponse = daprClient.saveState(STATE_STORE_NAME, stateKey, null, data, null);
//execute the save state action
saveResponse.block();
Expand All @@ -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<Void> 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
Expand Down Expand Up @@ -514,10 +515,11 @@ public void saveAndDeleteStateWithWrongEtag() {
//Create deferred action to delete an state sending the incorrect etag
Mono<Void> 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
Expand Down Expand Up @@ -545,7 +547,7 @@ public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() {
saveResponse.block();


//crate deferred action to retrieve the state
//create deferred action to retrieve the state
Mono<State<MyData>> response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions),
MyData.class);
//execute the retrieve of the state using options
Expand All @@ -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
Expand All @@ -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<Void> finalSaveResponse2 = saveResponse;
assertThrows(RuntimeException.class, () -> finalSaveResponse2.block());

response = daprClient.getState(STATE_STORE_NAME, new State(stateKey, null, stateOptions), MyData.class);
State<MyData> myLastDataResponse = response.block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -32,8 +33,7 @@ public final class BulkSubscribeAppResponse {
@JsonCreator
public BulkSubscribeAppResponse(
@JsonProperty("statuses") List<BulkSubscribeAppResponseEntry> statuses) {
this.statuses = new ArrayList<>();
this.statuses.addAll(statuses);
this.statuses = Collections.unmodifiableList(statuses);
}

public List<BulkSubscribeAppResponseEntry> getStatuses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GetBulkStateRequest {

private final List<String> keys;

private Map<String, String> metadata;
private Map<String, String> metadata = Collections.emptyMap();

private int parallelism = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GetConfigurationRequest {
*/
public GetConfigurationRequest(String storeName, List<String> 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<String, String> metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PublishEventRequest {

private String contentType;

private Map<String, String> metadata = new HashMap<>();
private Map<String, String> metadata = Collections.emptyMap();

/**
* Constructor for PublishEventRequest.
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/main/java/io/dapr/client/domain/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package io.dapr.client.domain;

import java.util.Collections;
import java.util.Map;

/**
Expand Down Expand Up @@ -116,7 +117,7 @@ public State(String key, T value, String etag, Map<String, String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SubscribeConfigurationRequest {
*/
public SubscribeConfigurationRequest(String storeName, List<String> 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<String, String> metadata) {
Expand Down
70 changes: 70 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,74 @@
<Match>
<Package name="~io\.dapr\.examples.*"/>
</Match>

<!-- Metadata is an unmodifiable map -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.ConfigurationItem"/>
<Method name="getMetadata"/>
</Match>

<!-- Keys is an unmodifiable list -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.GetBulkStateRequest"/>
<Method name="getKeys"/>
</Match>

<!-- Metadata is an unmodifiable map -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.GetBulkStateRequest"/>
<Method name="getMetadata"/>
</Match>

<!-- Keys is an unmodifiable list -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.GetConfigurationRequest"/>
<Method name="getKeys"/>
</Match>

<!-- Metadata is an unmodifiable map -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.PublishEventRequest"/>
<Method name="getMetadata"/>
</Match>

<!-- Statuses is an unmodifiable list -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.SaveStateRequest"/>
<Method name="getStates"/>
</Match>

<!-- Keys is an unmodifiable list -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.SubscribeConfigurationRequest"/>
<Method name="getKeys"/>
</Match>

<!-- Metadata is an unmodifiable map -->
<Match>
<Bug pattern="EI_EXPOSE_REP2"/>
<Class name="io.dapr.client.domain.State"/>
<Method name="&lt;init&gt;"/>
</Match>

<!-- Metadata is an unmodifiable map -->
<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<Class name="io.dapr.client.domain.State"/>
<Method name="getMetadata"/>
</Match>

<Match>
<Bug pattern="EI_EXPOSE_REP2"/>
<Class name="io.dapr.workflows.DaprWorkflowContextImpl"/>
<Method name="&lt;init&gt;"/>
</Match>

</FindBugsFilter>

0 comments on commit bbd3b20

Please sign in to comment.