You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to say that if the given method returns non-null, then the passed in value is non-null.
@Contract("null -> null")
publicstatic@NullableActivityactivityFromContext(@NullableContextcontext) {
// Only retrieves the base context if the supplied context is a ContextWrapper but not an// Activity, because Activity is a subclass of ContextWrapper.while (contextinstanceofContextWrapper) {
if (contextinstanceofActivity) return (Activity) context;
context = ((ContextWrapper) context).getBaseContext();
}
returnnull;
}
But this still gives a warning:
if (ContextUtils.activityFromContext(context) != null) {
mDialogCore = new DialogOverlayCore();
// Complains that context is nullable:
mDialogCore.initialize(context, mConfig, DialogOverlayImpl.this, mAsPanel);
mDialogCore.onWindowToken(window.getWindowToken());
}
Interesting! I feel like we should be able to handle this one, but I'll need to dig into the code more to see if there is some fundamental reason this is hard.
I think you're right, actually, that handling this case and inferring parameter nullness from the return nullness is kind of beyond what our code is set up to do right now. I'll think more, but probably we'll need to just update the docs.
I'd like to say that if the given method returns non-null, then the passed in value is non-null.
But this still gives a warning:
I suspect this might fall under:
If so, it'd be great to update the docs to say that contract support cannot infer parameters based on nullness of return types.
The text was updated successfully, but these errors were encountered: