Eclipse seems to do wrong analisys , method test1 is ok, but method test2 give the error:
Null type safety: The expression of type String needs unchecked conversion to conform to @NonNull
public class TestCase {
public Object o;
@NonNull
public Object test1() {
Object local = new Object();
return local;
}
@NonNull
public Object test2() {
o = new Object();
return o;
}
}
I suspect the problem is that you're returning a value which may have been changed by a different thread. It is possible for that method to return a null reference, basically. You can avoid that by using a temporary variable: