{"record":{"id":"08bfc57a7b269b0e","repo":"bumptech/glide","slug":"you-cannot-start-a-load-on-a-null-context","errorCode":null,"errorMessage":"You cannot start a load on a null Context","messagePattern":"You cannot start a load on a null Context","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java","lineNumber":90,"sourceCode":"          // TODO(b/27524013): Factor out this Glide.get() call.\n          Glide glide = Glide.get(context.getApplicationContext());\n          applicationManager =\n              factory.build(\n                  glide,\n                  new ApplicationLifecycle(),\n                  new EmptyRequestManagerTreeNode(),\n                  context.getApplicationContext());\n        }\n      }\n    }\n\n    return applicationManager;\n  }\n\n  @NonNull\n  public RequestManager get(@NonNull Context context) {\n    if (context == null) {\n      throw new IllegalArgumentException(\"You cannot start a load on a null Context\");\n    } else if (Util.isOnMainThread() && !(context instanceof Application)) {\n      if (context instanceof FragmentActivity) {\n        return get((FragmentActivity) context);\n      } else if (context instanceof ContextWrapper\n          // Only unwrap a ContextWrapper if the baseContext has a non-null application context.\n          // Context#createPackageContext may return a Context without an Application instance,\n          // in which case a ContextWrapper may be used to attach one.\n          && ((ContextWrapper) context).getBaseContext().getApplicationContext() != null) {\n        return get(((ContextWrapper) context).getBaseContext());\n      }\n    }\n\n    return getApplicationManager(context);\n  }\n\n  @NonNull\n  public RequestManager get(@NonNull FragmentActivity activity) {\n    if (Util.isOnBackgroundThread()) {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java#L72-L108","documentation":"IllegalArgumentException thrown by RequestManagerRetriever.get(Context) when the supplied Context is null. Glide requires a non-null Context (Application, Activity, FragmentActivity, or ContextWrapper) to scope the RequestManager lifecycle.","triggerScenarios":"Calling Glide.with(null), or Glide.with((Context) someField) where the field is null (e.g. in a detached fragment whose getContext() is null).","commonSituations":"Calling Glide.with() from a constructor or field that has not been initialized. Using Glide.with(getActivity()) after the activity has been destroyed and field nulled. Passing a nullable Context from an interop layer without null-checking.","solutions":["Use Glide.with(view) or Glide.with(applicationContext) where Context may be null.","Null-check the Context before calling Glide.with().","In fragments, prefer Glide.with(this) (the fragment) over Glide.with(getActivity())."],"exampleFix":"// before\nGlide.with(getActivity()).load(url).into(img); // getActivity() can be null\n// after\nContext ctx = getContext();\nif (ctx != null) {\n  Glide.with(ctx).load(url).into(img);\n}","handlingStrategy":"type-guard","validationCode":"// Null-check Context (or use View) before calling Glide.with().\nContext ctx = getView() != null ? getView().getContext() : null;\nif (ctx != null) {\n  Glide.with(ctx).load(url).into(img);\n}","typeGuard":"// Kotlin guard\nval ctx: Context? = view?.context\nif (ctx != null) Glide.with(ctx).load(url).into(img)","tryCatchPattern":null,"preventionTips":["Prefer Glide.with(view) which tolerates detached views better than null Context.","Null-check Context obtained from getActivity()/getContext() in callbacks.","Avoid holding Activity references that may be nulled on destroy."],"tags":["context","requestmanager","null-safety","lifecycle","android"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}