didi/DoKit · error · NullPointerException

{} must not be null

Error message

{} must not be null

What it means

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.

Source

Thrown at Android/dokit-leakcanary/src/main/java/com/squareup/leakcanary/Preconditions.java:27

 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.squareup.leakcanary;

final class Preconditions {

  /**
   * Returns instance unless it's null.
   *
   * @throws NullPointerException if instance is null
   */
  static <T> T checkNotNull(T instance, String name) {
    if (instance == null) {
      throw new NullPointerException(name + " must not be null");
    }
    return instance;
  }

  private Preconditions() {
    throw new AssertionError();
  }
}

View on GitHub (pinned to 626827cddb)

Solutions

  1. Identify which argument is null from the message's name token, then fix the caller to pass a valid value
  2. Null-check before calling: if (ref != null) refWatcher.watch(ref, 'tag')
  3. For optional references, skip watching when null rather than passing null through

Example fix

// before
refWatcher.watch(maybeNullService, "MyService");

// after
if (maybeNullService != null) {
  refWatcher.watch(maybeNullService, "MyService");
}
Defensive patterns

Strategy: validation

Validate before calling

if (reference != null && name != null) { refWatcher.watch(reference, name); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/cca176f79773806d. Report an issue: GitHub.