{"record":{"id":"951cad7081b6177d","repo":"Tencent/matrix","slug":"gettag-is-not-yet-init","errorCode":null,"errorMessage":"<getTag()> is not yet init!","messagePattern":"<getTag\\(\\)> is not yet init!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/BatteryMonitorPlugin.java","lineNumber":72,"sourceCode":"\n    @Override\n    public void onForeground(boolean isForeground) {\n        mDelegate.onForeground(isForeground);\n    }\n\n    @Override\n    public boolean isForeground() {\n        return mDelegate.isForeground();\n    }\n\n    public String getProcessName() {\n        if (sProcessName == null) {\n            synchronized (this) {\n                if (sProcessName == null) {\n                    Application application = getApplication();\n                    if (application == null) {\n                        if (!Matrix.isInstalled()) {\n                            throw new IllegalStateException(getTag() + \" is not yet init!\");\n                        }\n                        application = Matrix.with().getApplication();\n                    }\n                    sProcessName = MatrixUtil.getProcessName(application);\n                }\n            }\n        }\n        return sProcessName;\n    }\n\n    public String getPackageName() {\n        if (sPackageName == null) {\n            synchronized (this) {\n                if (sPackageName == null) {\n                    Application application = getApplication();\n                    if (application == null) {\n                        if (!Matrix.isInstalled()) {\n                            throw new IllegalStateException(getTag() + \" is not yet init!\");","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/BatteryMonitorPlugin.java#L54-L90","documentation":"BatteryMonitorPlugin.getProcessName() throws IllegalStateException(\"<tag> is not yet init!\") when it needs the Application reference and Matrix.isInstalled() is false — i.e. neither a cached application is available nor Matrix has been installed via Matrix.init(). The plugin depends on Matrix's Application reference to read the process name.","triggerScenarios":"Calling BatteryMonitorPlugin.getProcessName() before Matrix.init(application, ..., new BatteryMonitorPlugin(...)) when getApplication() returns null.","commonSituations":"Querying the plugin's processName during Application.attachBaseContext (Matrix not yet installed); constructing/querying the plugin in a content provider that runs before init; calling from unit tests without Matrix installed.","solutions":["Call Matrix.init(application, plugin...) in Application.onCreate before using the plugin.","Guard: only call getProcessName() after Matrix.isInstalled() returns true, otherwise fall back to MatrixUtil.getProcessName(context) with your own context.","Cache the process name yourself and skip the plugin accessor until initialization completes."],"exampleFix":"// before\nString proc = plugin.getProcessName(); // throws if Matrix not installed\n\n// after\nString proc = Matrix.isInstalled()\n        ? plugin.getProcessName()\n        : MatrixUtil.getProcessName(myApplication);","handlingStrategy":"validation","validationCode":"if (!Matrix.isInstalled()) {\n    // fallback path or defer the call until after Matrix.init()\n    return;\n}\nString procName = plugin.getProcessName();","typeGuard":null,"tryCatchPattern":"try {\n    String proc = plugin.getProcessName();\n} catch (IllegalStateException e) {\n    String proc = MatrixUtil.getProcessName(myApplicationContext);\n}","preventionTips":["Install Matrix in Application.onCreate before any plugin accessor use.","Guard plugin API calls behind Matrix.isInstalled().","Keep a locally cached process name as a fallback."],"tags":["android","initialization","battery","matrix"],"backgroundTag":"module-init-failed","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}