From 91728920975bd750ab01ac366468e00e30a633c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Fri, 21 Jun 2019 11:33:48 +0200 Subject: [PATCH] Fix NPE for repositories without properties --- .../src/main/java/sonia/scm/update/V1Properties.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/update/V1Properties.java b/scm-core/src/main/java/sonia/scm/update/V1Properties.java index 9347d584ce..7df65efdb6 100644 --- a/scm-core/src/main/java/sonia/scm/update/V1Properties.java +++ b/scm-core/src/main/java/sonia/scm/update/V1Properties.java @@ -6,9 +6,11 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import static java.util.Arrays.asList; import static java.util.Arrays.stream; +import static java.util.stream.Stream.empty; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "properties") @@ -32,7 +34,7 @@ public class V1Properties { } public Optional getOptional(String key) { - return properties.stream().filter(p -> key.equals(p.getKey())).map(V1Property::getValue).findFirst(); + return streamProps().filter(p -> key.equals(p.getKey())).map(V1Property::getValue).findFirst(); } public Optional getBoolean(String key) { @@ -44,10 +46,14 @@ public class V1Properties { } public boolean hasAny(String[] keys) { - return properties.stream().anyMatch(p -> stream(keys).anyMatch(k -> k.equals(p.getKey()))); + return streamProps().anyMatch(p -> stream(keys).anyMatch(k -> k.equals(p.getKey()))); } public boolean hasAll(String[] keys) { - return stream(keys).allMatch(k -> properties.stream().anyMatch(p -> k.equals(p.getKey()))); + return stream(keys).allMatch(k -> streamProps().anyMatch(p -> k.equals(p.getKey()))); + } + + private Stream streamProps() { + return properties == null? empty(): properties.stream(); } }