diff --git a/core/api/src/main/java/org/n52/sos/util/CollectionHelper.java b/core/api/src/main/java/org/n52/sos/util/CollectionHelper.java index c2afb0e00b..7d4f362e4c 100644 --- a/core/api/src/main/java/org/n52/sos/util/CollectionHelper.java +++ b/core/api/src/main/java/org/n52/sos/util/CollectionHelper.java @@ -55,6 +55,7 @@ * @since 4.0.0 */ public final class CollectionHelper { + private CollectionHelper() { } @@ -545,6 +546,5 @@ public static String[] svStringToArray(String sv, String separator) { } return split; } - } diff --git a/core/api/src/test/java/org/n52/sos/util/CollectionHelperTest.java b/core/api/src/test/java/org/n52/sos/util/CollectionHelperTest.java index 76a1e6403c..8540115a71 100644 --- a/core/api/src/test/java/org/n52/sos/util/CollectionHelperTest.java +++ b/core/api/src/test/java/org/n52/sos/util/CollectionHelperTest.java @@ -53,7 +53,8 @@ * */ public class CollectionHelperTest { - private final Set EMPTY_COLLECTION = new HashSet(0); + + private final Set EMPTY_COLLECTION = new HashSet<>(0); @Test public void should_return_empty_list_when_union_receives_null() { @@ -62,32 +63,32 @@ public void should_return_empty_list_when_union_receives_null() { @Test public void should_return_empty_list_when_unionOfListOfLists_receives_empty_list() { - final Collection> emptyList = new ArrayList>(0); + final Collection> emptyList = new ArrayList<>(0); assertThat(unionOfListOfLists(emptyList), is(EMPTY_COLLECTION)); } @Test public void should_return_union_of_values_without_duplicates() { - final Collection listA = new ArrayList(2); + final Collection listA = new ArrayList<>(2); listA.add("A"); listA.add("B"); - final Collection listB = new ArrayList(4); + final Collection listB = new ArrayList<>(4); listB.add("B"); listB.add("C"); listB.add(null); - final Collection listC = new ArrayList(2); + final Collection listC = new ArrayList<>(2); listC.add(""); - final Collection> col = new ArrayList>(4); + final Collection> col = new ArrayList<>(4); col.add(listA); col.add(listB); col.add(listC); col.add(null); col.add(new ArrayList(0)); - final Collection check = new HashSet(4); + final Collection check = new HashSet<>(4); check.add("A"); check.add("B"); check.add("C"); @@ -97,26 +98,26 @@ public void should_return_union_of_values_without_duplicates() { @Test public void isNotEmpty_should_return_true_if_map_is_not_empty() { - final Map map = new HashMap(1); + final Map map = new HashMap<>(1); map.put("key", "value"); assertThat(CollectionHelper.isNotEmpty(map), is(TRUE)); } @Test public void isNotEmpty_should_return_false_if_map_is_empty() { - final Map map = new HashMap(0); + final Map map = new HashMap<>(0); assertThat(CollectionHelper.isNotEmpty(map), is(FALSE)); } @Test public void isEmpty_should_return_true_if_map_is_empty() { - final Map map = new HashMap(0); + final Map map = new HashMap<>(0); assertThat(CollectionHelper.isEmpty(map), is(TRUE)); } @Test public void isEmpty_should_return_false_if_map_is_not_empty() { - final Map map = new HashMap(1); + final Map map = new HashMap<>(1); map.put("key", "value"); assertThat(CollectionHelper.isEmpty(map), is(FALSE)); } @@ -152,4 +153,5 @@ public void should_return_set_sorted_by_value() { assertThat(iterator.next(),is(3)); assertThat(iterator.next(),is(4)); } + } diff --git a/core/cache/src/main/java/org/n52/sos/cache/InMemoryCacheImpl.java b/core/cache/src/main/java/org/n52/sos/cache/InMemoryCacheImpl.java index 7dc6175295..a419555ad9 100644 --- a/core/cache/src/main/java/org/n52/sos/cache/InMemoryCacheImpl.java +++ b/core/cache/src/main/java/org/n52/sos/cache/InMemoryCacheImpl.java @@ -1359,11 +1359,14 @@ public void removeFeatureOfInterestForResultTemplate(final String resultTemplate @Override public void removeFeaturesOfInterestForOffering(final String offering) { notNullOrEmpty(OFFERING, offering); - LOG.trace("Removing featuresOfInterest for offering {}", offering); - for (String featureOfInterest : featuresOfInterestForOfferings.get(offering)) { - this.offeringsForFeaturesOfInterest.removeWithKey(featureOfInterest, offering); + // prevent NPEs in foreach of Map.get(..) + if (featuresOfInterestForOfferings.containsKey(offering)) { + LOG.trace("Removing featuresOfInterest for offering {}", offering); + for (String featureOfInterest : featuresOfInterestForOfferings.get(offering)) { + this.offeringsForFeaturesOfInterest.removeWithKey(featureOfInterest, offering); + } + this.featuresOfInterestForOfferings.remove(offering); } - this.featuresOfInterestForOfferings.remove(offering); } @Override