{"record":{"id":"a9ef93a9531e4af8","repo":"Tencent/matrix","slug":"name-must-not-be-null","errorCode":null,"errorMessage":"${name} must not be null","messagePattern":"(.+?) must not be null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-common/src/main/java/com/tencent/matrix/resource/common/utils/Preconditions.java","lineNumber":32,"sourceCode":" * limitations under the License.\n */\npackage com.tencent.matrix.resource.common.utils;\n\n/**\n * Created by tangyinsheng on 2017/6/2.\n *\n * This class is ported from LeakCanary.\n */\npublic final class Preconditions {\n\n    /**\n     * Returns instance unless it's null.\n     *\n     * @throws NullPointerException if instance is null\n     */\n    public static <T> T checkNotNull(T instance, String name) {\n        if (instance == null) {\n            throw new NullPointerException(name + \" must not be null\");\n        }\n        return instance;\n    }\n\n    private Preconditions() {\n        throw new AssertionError();\n    }\n}\n","sourceCodeStart":14,"sourceCodeEnd":41,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-common/src/main/java/com/tencent/matrix/resource/common/utils/Preconditions.java#L14-L41","documentation":"Preconditions.checkNotNull is a Guava-style helper that throws NullPointerException('<name> must not be null') when the given instance is null. It is used across matrix-resource-canary-common to validate constructor and method arguments early. The message names the parameter so the caller can identify which required value was missing.","triggerScenarios":"Passing null as any argument wrapped in Preconditions.checkNotNull(instance, \"name\") — e.g. null activity, null listener, null file path, or null config object supplied to ResourcePlugin/WatcherFactory APIs.","commonSituations":"Builder fields left unset before build(); initialization ordering where a dependency (e.g. application context, plugin listener) isn't ready; passing null intentionally to 'disable' a feature where the API demands a real object.","solutions":["Ensure the argument is non-null before calling; provide a default instance where the API allows.","Fix initialization order so the dependency exists before the canary component is constructed.","If the parameter is truly optional, use the API variant that accepts null or supply a no-op implementation.","Log/inspect the message's name field to identify exactly which argument was null."],"exampleFix":"// before\nwatcherFactory.setLeakProcessor(null);\n// after\nwatcherFactory.setLeakProcessor(new DefaultLeakProcessor(new DefaultHeapDump()));","handlingStrategy":"validation","validationCode":"if (arg == null) {\n    throw new IllegalArgumentException(\"arg must be provided before calling API\");\n}","typeGuard":"static <T> boolean isPresent(T v) { return v != null; }","tryCatchPattern":"try {\n    api.call(maybeNull);\n} catch (NullPointerException e) {\n    Log.e(TAG, \"Missing required argument: \" + e.getMessage(), e);\n}","preventionTips":["Check builder fields before build()","Run a startup assertion that all plugin dependencies are initialized","Pass no-op implementations instead of null for optional collaborators"],"tags":["null-check","preconditions","illegal-argument","android"],"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"}