Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix npe in delete sensor #547

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* @since 4.0.0
*/
public final class CollectionHelper {

private CollectionHelper() {
}

Expand Down Expand Up @@ -545,6 +546,5 @@ public static String[] svStringToArray(String sv, String separator) {
}
return split;
}


}
24 changes: 13 additions & 11 deletions core/api/src/test/java/org/n52/sos/util/CollectionHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
*
*/
public class CollectionHelperTest {
private final Set<String> EMPTY_COLLECTION = new HashSet<String>(0);

private final Set<String> EMPTY_COLLECTION = new HashSet<>(0);

@Test
public void should_return_empty_list_when_union_receives_null() {
Expand All @@ -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<? extends Collection<String>> emptyList = new ArrayList<Set<String>>(0);
final Collection<? extends Collection<String>> emptyList = new ArrayList<>(0);
assertThat(unionOfListOfLists(emptyList), is(EMPTY_COLLECTION));
}

@Test
public void should_return_union_of_values_without_duplicates() {
final Collection<String> listA = new ArrayList<String>(2);
final Collection<String> listA = new ArrayList<>(2);
listA.add("A");
listA.add("B");

final Collection<String> listB = new ArrayList<String>(4);
final Collection<String> listB = new ArrayList<>(4);
listB.add("B");
listB.add("C");
listB.add(null);

final Collection<String> listC = new ArrayList<String>(2);
final Collection<String> listC = new ArrayList<>(2);
listC.add("");

final Collection<Collection<String>> col = new ArrayList<Collection<String>>(4);
final Collection<Collection<String>> col = new ArrayList<>(4);
col.add(listA);
col.add(listB);
col.add(listC);
col.add(null);
col.add(new ArrayList<String>(0));

final Collection<String> check = new HashSet<String>(4);
final Collection<String> check = new HashSet<>(4);
check.add("A");
check.add("B");
check.add("C");
Expand All @@ -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<String, String> map = new HashMap<String, String>(1);
final Map<String, String> 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<String, String> map = new HashMap<String, String>(0);
final Map<String, String> map = new HashMap<>(0);
assertThat(CollectionHelper.isNotEmpty(map), is(FALSE));
}

@Test
public void isEmpty_should_return_true_if_map_is_empty() {
final Map<String, String> map = new HashMap<String, String>(0);
final Map<String, String> map = new HashMap<>(0);
assertThat(CollectionHelper.isEmpty(map), is(TRUE));
}

@Test
public void isEmpty_should_return_false_if_map_is_not_empty() {
final Map<String, String> map = new HashMap<String, String>(1);
final Map<String, String> map = new HashMap<>(1);
map.put("key", "value");
assertThat(CollectionHelper.isEmpty(map), is(FALSE));
}
Expand Down Expand Up @@ -152,4 +153,5 @@ public void should_return_set_sorted_by_value() {
assertThat(iterator.next(),is(3));
assertThat(iterator.next(),is(4));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down