I’m struggling with a null mismatch error in the below code with the Collectors.toSet() call:
Set<String> existingChannels = getThing().getChannelsOfGroup(CHANNEL_GROUP_DEVICES).stream()
.filter(ch -> Objects.requireNonNull(ch.getChannelTypeUID()).equals(channelType.getUID()))
.map(ch -> ch.getProperties().get(CHANNEL_PROPERTY_ID))
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Here is the error when I build via maven:
Null type mismatch (type annotations): required
'java.util.stream.@NonNull Collector<? super java.lang.@Nullable String,java.lang.Object,java.util.@NonNull Set<java.lang.@NonNull String>>' but this expression has type
'java.util.stream.@NonNull Collector<java.lang.@NonNull String,capture#of ?,java.util.@NonNull Set<java.lang.@NonNull String>>'
This does not show up as an issue in Eclipse, but only when I build via maven externally.
- I presume Eclipse and mvn are looking at the same eea file to get the annotations - any idea what is different between the two?
- I can fix this by declaring this as a Set<@Nullable String>, however that seems like a “hack” workaround and in reading up on the eea and standard libraries, the right way to address is in the eea file.
- Here is the toSet() annotation in the eea file - i’m struggling to interpret this to see if there is an error.
toSet
<T:Ljava/lang/Object;>()Ljava/util/stream/Collector<TT;*Ljava/util/Set<TT;>;>;
<T:Ljava/lang/Object;>()L1java/util/stream/Collector<TT;*L1java/util/Set<TT;>;>;
Would appreciate some help from someone who has more experience in eea and these types of issues.