I've updated Android Studio to the latest version, 1.2. I've also recently updated other components like the Android Gradle Extensions.
Now I'm getting warned on methods that I had previously annotated as NotNull. The warning is: Expression might evaluate to null but is returned by the method declared as @NotNull
Here's an example:
public class MyApplication extends Application {
private static SharedPreferences sPrefs = null;
/**
* Corresponds to a string value.
*
* @see #setDeviceInfo(String, String, String)
*/
private static final String PREF_DEVICE_INFO_DEVICE_ADDRESS = "deviceaddress";
@Override
public void onCreate() {
super.onCreate();
sPrefs = PreferenceManager.getDefaultSharedPreferences(this);
}
@NonNull
public static String getDeviceAddress() {
return sPrefs.getString(PREF_DEVICE_INFO_DEVICE_ADDRESS, "");
}
}
I would think that there is no way for getString to return null in this case because I have have set a default value, ""
And even when I look at the implementation of getString (in API 22 anyway) it would seem that this is a case where android studio has simply ignored the fact that my default value is not null and made a false assumption that the default value could be null.
API 22 implementation:
public String getString(String key, String defValue) {
synchronized (this) {
awaitLoadedLocked();
String v = (String)mMap.get(key);
return v != null ? v : defValue;
}
}
Still I need the community to put me at ease or point out what I'm missing before I move on.