Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
fix NPE on getValues for unknown key
Browse files Browse the repository at this point in the history
  • Loading branch information
rickfast committed Dec 21, 2016
1 parent 2ca6133 commit ec0f9ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/com/orbitz/consul/KeyValueClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import retrofit2.http.*;

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

Expand Down Expand Up @@ -144,7 +145,9 @@ public List<Value> getValues(String key, QueryOptions queryOptions) {

query.put("recurse", "true");

return extract(api.getValue(trimLeadingSlash(key), query), NOT_FOUND_404);
List<Value> result = extract(api.getValue(trimLeadingSlash(key), query), NOT_FOUND_404);

return result == null ? Collections.<Value>emptyList() : result;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/orbitz/consul/KeyValueTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,10 @@ public void testBasicTxn() throws Exception {
assertEquals(value, keyValueClient.getValueAsString(key).get());
assertEquals(response.getIndex(), keyValueClient.getValue(key).get().getModifyIndex());
}

@Test
public void testUnknownKey() {
List<String> shouldBeEmpty = client.keyValueClient().getValuesAsString("unknownKey");
assertTrue(shouldBeEmpty.isEmpty());
}
}

0 comments on commit ec0f9ac

Please sign in to comment.