Tencent/matrix · error · IllegalStateException
<getTag()> is not yet init!
Error message
<getTag()> is not yet init!
What it means
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.
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.
Example fix
// before
String proc = plugin.getProcessName(); // throws if Matrix not installed
// after
String proc = Matrix.isInstalled()
? plugin.getProcessName()
: MatrixUtil.getProcessName(myApplication); Defensive patterns
Strategy: validation
Validate before calling
if (!Matrix.isInstalled()) {
// fallback path or defer the call until after Matrix.init()
return;
}
String procName = plugin.getProcessName(); Try / catch
try {
String proc = plugin.getProcessName();
} catch (IllegalStateException e) {
String proc = MatrixUtil.getProcessName(myApplicationContext);
} Prevention
- 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.
When it happens
Trigger: Calling BatteryMonitorPlugin.getProcessName() before Matrix.init(application, ..., new BatteryMonitorPlugin(...)) when getApplication() returns null.
Common situations: 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.
Related errors
- Call #init() first!
- Matrix init, Matrix should not be null.
- you must init Matrix sdk first
- matrix init, application is null
- plugin duplicate init, application or plugin listener is…
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/951cad7081b6177d.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/BatteryMonitorPlugin.java:72
@Override
public void onForeground(boolean isForeground) {
mDelegate.onForeground(isForeground);
}
@Override
public boolean isForeground() {
return mDelegate.isForeground();
}
public String getProcessName() {
if (sProcessName == null) {
synchronized (this) {
if (sProcessName == null) {
Application application = getApplication();
if (application == null) {
if (!Matrix.isInstalled()) {
throw new IllegalStateException(getTag() + " is not yet init!");
}
application = Matrix.with().getApplication();
}
sProcessName = MatrixUtil.getProcessName(application);
}
}
}
return sProcessName;
}
public String getPackageName() {
if (sPackageName == null) {
synchronized (this) {
if (sPackageName == null) {
Application application = getApplication();
if (application == null) {
if (!Matrix.isInstalled()) {
throw new IllegalStateException(getTag() + " is not yet init!");View on GitHub (pinned to 3b8293bd65)