{"record":{"id":"cca176f79773806d","repo":"didi/DoKit","slug":"must-not-be-null","errorCode":null,"errorMessage":"{} must not be null","messagePattern":"(.+?) must not be null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"Android/dokit-leakcanary/src/main/java/com/squareup/leakcanary/Preconditions.java","lineNumber":27,"sourceCode":" *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage com.squareup.leakcanary;\n\nfinal class Preconditions {\n\n  /**\n   * Returns instance unless it's null.\n   *\n   * @throws NullPointerException if instance is null\n   */\n  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":9,"sourceCodeEnd":36,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit-leakcanary/src/main/java/com/squareup/leakcanary/Preconditions.java#L9-L36","documentation":"Preconditions.checkNotNull() is LeakCanary's internal null-check helper: it returns the instance when non-null and throws NullPointerException with '<name> must not be null' otherwise. It is used at API boundaries (watch(), build(), etc.) to fail fast with a self-documenting message instead of an anonymous NPE deep in analysis.","triggerScenarios":"Calling an API guarded by checkNotNull with null: e.g. RefWatcher.watch(reference, name) with a null reference, or builder/analysis methods receiving null context/file/reference. The 'name' in the message identifies which argument was null.","commonSituations":"Watching references that may legitimately be null (e.g. activity fields not yet initialized), passing a null Context in instrumentation or tests, or a null heap dump file path after a failed dump.","solutions":["Identify which argument is null from the message's name token, then fix the caller to pass a valid value","Null-check before calling: if (ref != null) refWatcher.watch(ref, 'tag')","For optional references, skip watching when null rather than passing null through"],"exampleFix":"// before\nrefWatcher.watch(maybeNullService, \"MyService\");\n\n// after\nif (maybeNullService != null) {\n  refWatcher.watch(maybeNullService, \"MyService\");\n}","handlingStrategy":"validation","validationCode":"if (reference != null && name != null) { refWatcher.watch(reference, name); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check nullable references before watch(); the message's name token tells you which argument was null","Skip watching for genuinely optional/absent references"],"tags":["leakcanary","null-check","android","java"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}