Skip to content

Commit fd98d59

Browse files
committed
fix: don't allow qualifiers to contain nullable values
This fixes the warning "Assigning a collection of nullable elements into a collection of non-null elements" which was a difference between what `PurlParameters::getQualifiers` returns and what `PackageURL::new` expects. So far, we don't have an example of qualifiers with `null` elements, but we can just return `"null"` instead which should have the same effect when comparing values. Simplify the creation of the qualifiers map from the `JSONObject` by using `Collectors::toMap`.
1 parent 86bebd8 commit fd98d59

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/test/java/com/github/packageurl/PurlParameters.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import java.io.IOException;
2727
import java.io.InputStream;
2828
import java.util.Collections;
29-
import java.util.HashMap;
3029
import java.util.Map;
3130
import java.util.Objects;
31+
import java.util.stream.Collectors;
3232
import java.util.stream.IntStream;
3333
import java.util.stream.Stream;
3434
import org.json.JSONArray;
@@ -98,10 +98,7 @@ private PurlParameters(
9898
this.version = version;
9999
if (qualifiers != null) {
100100
this.qualifiers = qualifiers.toMap().entrySet().stream()
101-
.collect(
102-
HashMap::new,
103-
(m, e) -> m.put(e.getKey(), Objects.toString(e.getValue(), null)),
104-
HashMap::putAll);
101+
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Objects.toString(entry.getValue())));
105102
} else {
106103
this.qualifiers = Collections.emptyMap();
107104
}
@@ -124,7 +121,7 @@ private PurlParameters(
124121
return version;
125122
}
126123

127-
public Map<String, @Nullable String> getQualifiers() {
124+
public Map<String, String> getQualifiers() {
128125
return Collections.unmodifiableMap(qualifiers);
129126
}
130127

0 commit comments

Comments
 (0)