{"record":{"id":"2cee705a2105de38","repo":"lingochamp/FileDownloader","slug":"the-provided-context-must-not-be-null","errorCode":null,"errorMessage":"the provided context must not be null!","messagePattern":"the provided context must not be null!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/FileDownloader.java","lineNumber":103,"sourceCode":"     */\n    public static DownloadMgrInitialParams.InitCustomMaker setupOnApplicationOnCreate(\n            Application application) {\n        final Context context = application.getApplicationContext();\n        FileDownloadHelper.holdContext(context);\n\n        DownloadMgrInitialParams.InitCustomMaker customMaker =\n                new DownloadMgrInitialParams.InitCustomMaker();\n        CustomComponentHolder.getImpl().setInitCustomMaker(customMaker);\n\n        return customMaker;\n    }\n\n    /**\n     * @deprecated please use {@link #setup(Context)} instead.\n     */\n    public static void init(final Context context) {\n        if (context == null) {\n            throw new IllegalArgumentException(\"the provided context must not be null!\");\n        }\n\n        setup(context);\n    }\n\n\n    /**\n     * @deprecated please using {@link #setupOnApplicationOnCreate(Application)} instead.\n     */\n    public static void init(final Context context,\n                            final DownloadMgrInitialParams.InitCustomMaker maker) {\n        if (FileDownloadLog.NEED_LOG) {\n            FileDownloadLog.d(FileDownloader.class, \"init Downloader with params: %s %s\",\n                    context, maker);\n        }\n\n        if (context == null) {\n            throw new IllegalArgumentException(\"the provided context must not be null!\");","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/FileDownloader.java#L85-L121","documentation":"FileDownloader.init(Context) (deprecated in favor of setup(Context)) throws IllegalArgumentException when the passed Context is null. The library needs a valid application context to set up its service components.","triggerScenarios":"Calling FileDownloader.getImpl().init(null) directly, or init(context) where context comes from getActivity()/getContext() returning null (e.g. in a detached fragment).","commonSituations":"Initializing in a Fragment after detachment; passing a Context field assigned later; calling init before onCreate completes.","solutions":["Use a guaranteed application context: context.getApplicationContext().","Prefer the non-deprecated FileDownloader.getImpl().setup(context).","Guard with a null check before init, and initialize in Application.onCreate.","If in a Fragment, use requireContext().getApplicationContext() only when attached."],"exampleFix":"// before\nFileDownloader.getImpl().init(getActivity());\n\n// after\nContext appContext = getApplicationContext();\nif (appContext != null) {\n    FileDownloader.getImpl().setup(appContext);\n}","handlingStrategy":"validation","validationCode":"if (context == null) return; // or fail fast\nFileDownloader.getImpl().setup(context.getApplicationContext());","typeGuard":"boolean hasValidContext(Context c) { return c != null && c.getApplicationContext() != null; }","tryCatchPattern":"try { FileDownloader.getImpl().setup(context); } catch (IllegalArgumentException e) { deferInitUntilContextAvailable(); }","preventionTips":["Initialize FileDownloader in Application.onCreate with getApplicationContext().","Avoid Fragment getContext() for library init.","Migrate from deprecated init() to setup()."],"tags":["android","null-argument","initialization","context"],"backgroundTag":"null-argument","analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}