{"record":{"id":"30a9839c20395c0a","repo":"Tencent/matrix","slug":"reporter-null","errorCode":null,"errorMessage":"reporter == null","messagePattern":"reporter == null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-io-canary/src/main/java/com/tencent/matrix/iocanary/detect/MatrixCloseGuard.java","lineNumber":152,"sourceCode":"        }\n        return new MatrixCloseGuard();\n    }\n\n    /**\n     * Used to enable or disable CloseGuard. Note that CloseGuard only\n     * warns if it is enabled for both allocation and finalization.\n     */\n    public static void setEnabled(boolean enabled) {\n        sENABLED = enabled;\n    }\n\n    /**\n     * Used to replace default Reporter used to warn of CloseGuard\n     * violations. Must be non-null.\n     */\n    public static void setReporter(Reporter reporter) {\n        if (reporter == null) {\n            throw new NullPointerException(\"reporter == null\");\n        }\n        sREPORTER = reporter;\n    }\n\n    /**\n     * Returns non-null CloseGuard.Reporter.\n     */\n    public static Reporter getReporter() {\n        return sREPORTER;\n    }\n\n    private MatrixCloseGuard() {\n    }\n\n    /**\n     * If CloseGuard is enabled, {@code open} initializes the instance\n     * with a warning that the caller should have explicitly called the\n     * {@code closer} method instead of relying on finalization.","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-io-canary/src/main/java/com/tencent/matrix/iocanary/detect/MatrixCloseGuard.java#L134-L170","documentation":"MatrixCloseGuard.setReporter() replaces the Reporter used to warn about CloseGuard violations (unclosed resources). The API contract requires a non-null reporter, so passing null throws NullPointerException(\"reporter == null\"). This mirrors the framework CloseGuard behavior Matrix re-implements for IO leak detection.","triggerScenarios":"Calling MatrixCloseGuard.setReporter(null) — typically during teardown/reset of IoCanary, or when the reporter is stored in a field that was never initialized before being passed in.","commonSituations":"An app lifecycle component clearing listeners by setting the reporter to null instead of using a proper disable/uninstall API; a DI-furnished reporter that is null in a debug/early-init build variant; refactoring that renamed the reporter field but left a null default.","solutions":["Never pass null — supply a real Reporter implementation (e.g. the IoCanary DefaultReporter) or simply stop calling setReporter().","If you want to stop reporting, call the appropriate Matrix disable/close API instead of setting a null reporter.","Null-check or lazily create the reporter before invoking setReporter().","If the reporter comes from DI/configuration, assert it is initialized during app startup."],"exampleFix":"// before\nMatrixCloseGuard.setReporter(null); // teardown attempt\n// after\nMatrixCloseGuard.setReporter(new MatrixCloseGuard.Reporter() {\n    @Override public void closeLeak(String where, String why) { /* log or report */ }\n});","handlingStrategy":"type-guard","validationCode":"if (reporter != null) {\n    MatrixCloseGuard.setReporter(reporter);\n}","typeGuard":"boolean isValidReporter(MatrixCloseGuard.Reporter r) {\n    return r != null;\n}","tryCatchPattern":"try {\n    MatrixCloseGuard.setReporter(reporter);\n} catch (NullPointerException e) {\n    MatrixLog.e(TAG, \"setReporter called with null; keeping previous reporter\");\n}","preventionTips":["Never pass null to setReporter; to stop reporting use Matrix's disable/uninstall API.","Initialize the reporter before any code path that can call setReporter.","Guard DI-provided reporters with an not-null assertion at startup."],"tags":["null-check","io-canary","closeguard","reporter"],"backgroundTag":"null-argument","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"}