{"record":{"id":"567acb1d09435a64","repo":"bilibili/DanmakuFlameMaster","slug":"context-is-null","errorCode":null,"errorMessage":"context is null","messagePattern":"context is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"DanmakuFlameMaster/src/main/java/master/flame/danmaku/controller/DrawTask.java","lineNumber":87,"sourceCode":"    private BaseDanmaku mLastDanmaku;\r\n\r\n    private Danmakus mLiveDanmakus = new Danmakus(Danmakus.ST_BY_LIST);\r\n\r\n    private IDanmakus mRunningDanmakus;\r\n\r\n    private boolean mRequestRender;\r\n\r\n    private ConfigChangedCallback mConfigChangedCallback = new ConfigChangedCallback() {\r\n        @Override\r\n        public boolean onDanmakuConfigChanged(DanmakuContext config, DanmakuConfigTag tag, Object... values) {\r\n            return DrawTask.this.onDanmakuConfigChanged(config, tag, values);\r\n        }\r\n    };\r\n\r\n    public DrawTask(DanmakuTimer timer, DanmakuContext context,\r\n            TaskListener taskListener) {\r\n        if (context == null) {\r\n            throw new IllegalArgumentException(\"context is null\");\r\n        }\r\n        mContext = context;\r\n        mDisp = context.getDisplayer();\r\n        mTaskListener = taskListener;\r\n        mRenderer = new DanmakuRenderer(context);\r\n        mRenderer.setOnDanmakuShownListener(new IRenderer.OnDanmakuShownListener() {\r\n\r\n            @Override\r\n            public void onDanmakuShown(BaseDanmaku danmaku) {\r\n                if (mTaskListener != null) {\r\n                    mTaskListener.onDanmakuShown(danmaku);\r\n                }\r\n            }\r\n        });\r\n        mRenderer.setVerifierEnabled(mContext.isPreventOverlappingEnabled() || mContext.isMaxLinesLimited());\r\n        initTimer(timer);\r\n        Boolean enable = mContext.isDuplicateMergingEnabled();\r\n        if (enable != null) {\r","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/bilibili/DanmakuFlameMaster/blob/e2846461a09e33720a049f628f09c653f55531f0/DanmakuFlameMaster/src/main/java/master/flame/danmaku/controller/DrawTask.java#L69-L105","documentation":"DrawTask's constructor requires a non-null DanmakuContext; it immediately derives the Displayer and DanmakuRenderer from it, so a null context would make the whole draw pipeline unusable. The library fails fast with IllegalArgumentException rather than NPE-ing later during rendering.","triggerScenarios":"Calling new DrawTask(timer, null, taskListener), or creating it indirectly (e.g. DanmakuView/DanmakuSurfaceView initialize paths) after DanmakuContext was never created via DanmakuContext.create().","commonSituations":"Forgetting to call DanmakuContext.create() before preparing the danmaku view; passing a context variable that is assigned asynchronously and still null when the draw task is built; custom controller code constructing DrawTask manually.","solutions":["Create a DanmakuContext first with DanmakuContext.create() and pass it to the constructor.","Check that the variable passed as context is assigned before the DrawTask/DanmakuView setup runs.","If using DanmakuView, ensure prepare() is called after the view has initialized its own context, not with a hand-built null context.","Wrap the setup call in a null check or Objects.requireNonNull(context) at the call site to catch it early."],"exampleFix":"// before\nDrawTask task = new DrawTask(timer, null, listener);\n// after\nDanmakuContext context = DanmakuContext.create();\nDrawTask task = new DrawTask(timer, context, listener);","handlingStrategy":"validation","validationCode":"if (context == null) { throw new IllegalStateException(\"call DanmakuContext.create() before constructing DrawTask\"); }\nDrawTask task = new DrawTask(timer, context, listener);","typeGuard":"boolean hasContext = (context != null);","tryCatchPattern":"try {\n    DrawTask task = new DrawTask(timer, context, listener);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"DrawTask needs a DanmakuContext\", e);\n    context = DanmakuContext.create();\n}","preventionTips":["Always create the context via DanmakuContext.create() before preparing the danmaku view.","Never pass a possibly-async-assigned context into view setup; await its assignment first.","Assert non-null context in your own wrapper around DrawTask."],"tags":["android","danmaku","null-argument","constructor"],"backgroundTag":"null-argument","analyzedSha":"e2846461a09e33720a049f628f09c653f55531f0","analyzedAt":"2026-09-10T14:31:54.917Z","contentChangedAt":"2026-09-10T14:31:54.917Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}