Reputation: 433
I am trying to find the right combination of nullness annotations and nullness checking functions in my project. I deal with a lot of String variables that have the possibility of being null, and need to check in a lot of places whether these variables are blank or not. A situation like below occurs frequently...
private void someMethod(SomeObject obj) {
@Nullable String nullableStr = obj.getStrThatCouldBeNull();
if (StringUtils.isNotBlank(nullableStr)) {
doSomething(nullableStr);
}
}
The only issue is that the CharSequence argument to StringUtils.isNotBlank is not annotated with any @Nullable annotations, so the java compiler gives me a warning like....
[argument.type.incompatible] incompatible types in argument.
found : @Initialized @Nullable CharSequence
required: @Initialized @NonNull CharSequence
How can I achieve my desired outcome: nullness annotations I can use for string with a nullness/blank-string check, and also not get warnings from the compiler? The above code works if I annotate the method with @SupressWarning("argument.type.incompatible"), but I would prefer to not have to add this annotation to every method where this happens, which is a fair amount in the project.
Upvotes: 0
Views: 134