{"record":{"id":"ddbce46f1223280a","repo":"gyf-dev/ImmersionBar","slug":"message-variable-e-g-activity-is-null-fragm","errorCode":null,"errorMessage":"message (variable, e.g. \"activity is null\", \"fragment is null\")","messagePattern":"message \\(variable, e\\.g\\. \"activity is null\", \"fragment is null\"\\)","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"immersionbar/src/main/java/com/gyf/immersionbar/RequestManagerRetriever.java","lineNumber":379,"sourceCode":"                putPendingSupportFragment(fm, tag, fragment);\n                fm.beginTransaction().add(fragment, tag).commitAllowingStateLoss();\n                mHandler.obtainMessage(ID_REMOVE_SUPPORT_FRAGMENT_MANAGER, new PendingFragment(fm, tag)).sendToTarget();\n            }\n        }\n        if (destroy) {\n            if (mPendingSupportRemoveFragments.get(tag) == null) {\n                mPendingSupportRemoveFragments.put(tag, fragment);\n                fm.beginTransaction().remove(fragment).commitAllowingStateLoss();\n                mHandler.obtainMessage(ID_REMOVE_SUPPORT_FRAGMENT_MANAGER_REMOVE, tag).sendToTarget();\n            }\n            return null;\n        }\n        return fragment;\n    }\n\n    private static <T> void checkNotNull(@Nullable T arg, @NonNull String message) {\n        if (arg == null) {\n            throw new NullPointerException(message);\n        }\n    }\n\n    private static class PendingFragment {\n        final Object fragmentManager;\n        final String tag;\n\n        PendingFragment(Object fragmentManager, String tag) {\n            this.fragmentManager = fragmentManager;\n            this.tag = tag;\n        }\n    }\n}\n","sourceCodeStart":361,"sourceCodeEnd":393,"githubUrl":"https://github.com/gyf-dev/ImmersionBar/blob/8cac10cd83d809eac54f42b37f92340c4a25c4ac/immersionbar/src/main/java/com/gyf/immersionbar/RequestManagerRetriever.java#L361-L393","documentation":"RequestManagerRetriever.checkNotNull throws NullPointerException with a caller-provided message (e.g. \"activity is null\", \"fragment is null\") when an argument to get()/supportFragmentGet() etc. is null. The library cannot attach its hidden support fragment without a live context owner, so it fails fast.","triggerScenarios":"Calling the retriever's get(Context)/get(Fragment) with a null Activity, null Fragment, or a context whose unwrapped activity is null (Application context, detached fragment).","commonSituations":"Requesting fragment manager access from a detached Fragment; passing applicationContext where an Activity is required; lifecycle races where the fragment was detached before the lookup; manually invoking retriever code rather than the public facade.","solutions":["Ensure a non-null, started Activity or attached Fragment is passed to get()","Unwrap ContextWrapper to verify an Activity exists before calling","Null-check the source (getActivity()/getParentFragment()) and retry after attachment"],"exampleFix":"// before\nFragment f = retriever.get(fragment.getActivity()); // activity may be null\n// after\nActivity activity = fragment.getActivity();\nif (activity != null) {\n    Fragment f = retriever.get(activity);\n}","handlingStrategy":"type-guard","validationCode":"if (activity != null) { retriever.get(activity); }","typeGuard":"Activity unwrapActivity(Context c) { while (c instanceof ContextWrapper) { if (c instanceof Activity) return (Activity) c; c = ((ContextWrapper) c).getBaseContext(); } return null; }","tryCatchPattern":"try { retriever.get(context); } catch (NullPointerException e) { Log.e(TAG, \"no activity available: \" + e.getMessage()); }","preventionTips":["Never pass Application context where an Activity is required","Check fragment.getActivity() != null before lookups","Avoid retriever calls from detached fragments or background threads"],"tags":["android","null-check","lifecycle","npe"],"backgroundTag":"null-argument","analyzedSha":"8cac10cd83d809eac54f42b37f92340c4a25c4ac","analyzedAt":"2026-09-08T11:52:01.757Z","contentChangedAt":"2026-09-08T11:52:01.757Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}