Skip to content

Commit

Permalink
fix: Add defensive code to prevent metadata containing null key. (#1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
ouaibsky committed Nov 29, 2021
1 parent ff6df57 commit 58b8815
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Expand Up @@ -18,6 +18,7 @@

import java.net.URI;
import java.util.Map;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -147,7 +148,9 @@ protected URI getServiceUrl(ServiceInstance instance) {
}

protected Map<String, String> getMetadata(ServiceInstance instance) {
return (instance.getMetadata() != null) ? instance.getMetadata() : emptyMap();
return (instance.getMetadata() != null) ? instance.getMetadata().entrySet().stream()
.filter((e) -> e.getKey() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
: emptyMap();
}

public void setManagementContextPath(String managementContextPath) {
Expand Down
Expand Up @@ -78,11 +78,12 @@ public static Tags from(Map<String, ?> map, @Nullable String prefix) {
}

String flatPrefix = prefix + ".";
return from(map.entrySet().stream().filter((e) -> e.getKey().toLowerCase().startsWith(flatPrefix))
return from(map.entrySet().stream().filter((e) -> e.getKey() != null)
.filter((e) -> e.getKey().toLowerCase().startsWith(flatPrefix))
.collect(toLinkedHashMap((e) -> e.getKey().substring(flatPrefix.length()), Map.Entry::getValue)));
}

return new Tags(map.entrySet().stream()
return new Tags(map.entrySet().stream().filter((e) -> e.getKey() != null)
.collect(toLinkedHashMap(Map.Entry::getKey, (e) -> Objects.toString(e.getValue()))));
}

Expand Down

0 comments on commit 58b8815

Please sign in to comment.