I’m trying to work on the Chromecast binding a bit, and while this isn’t neither new nor a showstopper, it just annoys me to have a lot of warnings everywhere, because they drown out the “real” warnings that I might need to see.
I have picked one specific example here now, but it’s just an example - the same or a similar issue is found many places in the code.
This is my “example code”:
MediaStatusResponse mediaStatusResponse = event.getData(MediaStatusResponse.class);
if (mediaStatusResponse == null) {
statusUpdater.updateMediaStatus(null);
} else {
List<MediaStatus> mediaStatuses = mediaStatusResponse.getStatuses();
for (MediaStatus mediaStatus : mediaStatuses) {
statusUpdater.updateMediaStatus(mediaStatus);
}
}
event.getData() is defined as such:
/**
* Tries to cast the event data to the specified type and return it.
*
* @param <U> the event data type.
* @param cls the {@link Class} of the event data type.
* @return The event data cast to the specified type or {@code null}.
*/
@Nullable
<U> U getData(Class<U> cls);
There should be no doubt that it can return null.
However, this is what Eclipse says:
The view of the JavaDoc for the method reveals the extent of the confusion:
It claims that the method is both @NonNull and @Nullable at the same time.
I’ve tried all kind of creative ways to apply @NonNullByDefault({}) to no avail. It is simply adamant that the method is @NonNull when it in fact is @Nullable. I’ve even tried removing @NonNullByDefault from the class, which usually resolves all “null weirdness”, but in this case, it makes no difference.
I just can’t fathom from where it gets the idea that the method is @NonNull - and I can’t find a way to tell it that it’s wrong.
I’ve used Eclipse a lot, and I’ve never seen this issue before, so I’m assuming that this is caused by something in the way OH is configured. I’ve noticed that lastnpe is in use by OH in some way, although I have no idea exactly how. Could this be the cause of the confusion?
Is there anything I can do to get rid of these false warnings - because they end up making the real warnings very hard to spot. I usually don’t “leave” a class until the entire file is without warnings, and I look for warning icons in Package Explorer to quickly find the culprits. But, when everything is full of these false warnings, my “usual process” crash and burn.
I obviously don’t want to use @SuppressWarnings("null"), since it will hide real problems as well.
Even worse, I also get a “unused code” warning here because of the erroneous conclusion it draws about nullness.

