Tencent/matrix · error · RuntimeException
plugin duplicate init, application or plugin listener is…
Error message
plugin duplicate init, application or plugin listener is not null
What it means
Plugin.init(Application, PluginListener) stores the app and listener exactly once; calling it again while either field is still set means the plugin is being re-initialized and throws to protect state consistency.
Solutions
- Call init only once per plugin instance; create fresh Plugin instances if re-initialization is needed.
- Avoid calling Matrix.init more than once per process.
- In tests, construct new plugin objects per test instead of reusing them.
Example fix
// before matrixPlugin.init(app, listener); matrixPlugin.init(app, listener2); // after matrixPlugin.init(app, listener); // create a new instance if re-init is required Plugin fresh = new MyPlugin(); fresh.init(app, listener2);
Defensive patterns
Strategy: validation
Validate before calling
if (plugin.getApplication() == null && plugin.getPluginListener() == null) {
plugin.init(app, listener);
} Try / catch
try {
plugin.init(app, listener);
} catch (RuntimeException e) {
Log.e(TAG, "plugin double init", e);
} Prevention
- Call init exactly once per plugin instance
- Never call Matrix.init twice in one process
- Create fresh plugins for each Matrix build in tests
When it happens
Trigger: Calling plugin.init(app, listener) twice; Matrix.init being invoked twice with a Builder containing the same plugin instances.
Common situations: Re-calling Matrix.init on config change or hot-restart; adding the same plugin objects to two Matrix instances; re-running Application.onCreate logic in tests.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Matrix init, Matrix should not be null.
- you must init Matrix sdk first
- matrix init, application is null
- plugin with tag is already exist
- plugin start, but plugin has been already destroyed
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/6235731ef1702784.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/plugin/Plugin.java:54
private static final String TAG = "Matrix.Plugin";
public static final int PLUGIN_CREATE = 0x00;
public static final int PLUGIN_INITED = 0x01;
public static final int PLUGIN_STARTED = 0x02;
public static final int PLUGIN_STOPPED = 0x04;
public static final int PLUGIN_DESTROYED = 0x08;
private PluginListener pluginListener;
private Application application;
private boolean isSupported = true;
private int status = PLUGIN_CREATE;
@Override
public void init(Application app, PluginListener listener) {
if (application != null || pluginListener != null) {
throw new RuntimeException("plugin duplicate init, application or plugin listener is not null");
}
status = PLUGIN_INITED;
this.application = app;
this.pluginListener = listener;
listener.onInit(this);
ProcessUILifecycleOwner.INSTANCE.addListener(this);
}
@Override
public void onDetectIssue(Issue issue) {
if (issue.getTag() == null) {
// set default tag
issue.setTag(getTag());
}
issue.setPlugin(this);
JSONObject content = issue.getContent();
// add tag and type for default
try {View on GitHub (pinned to 3b8293bd65)