didi/DoKit · error · IllegalArgumentException

Field {} does not exists

Error message

Field {} does not exists

What it means

HahaHelper.fieldValue() linearly scans a ClassInstance's field values for one whose field name equals fieldName and throws IllegalArgumentException when no such field exists. It is the lookup primitive used by HeapAnalyzer for KeyedWeakReference fields like 'key' and 'referent'.

Source

Thrown at Android/dokit-leakcanary/src/main/java/com/squareup/leakcanary/HahaHelper.java:178

  }

  private static boolean isByteArray(Object value) {
    return value instanceof ArrayInstance && ((ArrayInstance) value).getArrayType() == Type.BYTE;
  }

  static List<ClassInstance.FieldValue> classInstanceValues(Instance instance) {
    ClassInstance classInstance = (ClassInstance) instance;
    return classInstance.getValues();
  }

  @SuppressWarnings({ "unchecked", "TypeParameterUnusedInFormals" })
  static <T> T fieldValue(List<ClassInstance.FieldValue> values, String fieldName) {
    for (ClassInstance.FieldValue fieldValue : values) {
      if (fieldValue.getField().getName().equals(fieldName)) {
        return (T) fieldValue.getValue();
      }
    }
    throw new IllegalArgumentException("Field " + fieldName + " does not exists");
  }

  static boolean hasField(List<ClassInstance.FieldValue> values, String fieldName) {
    for (ClassInstance.FieldValue fieldValue : values) {
      if (fieldValue.getField().getName().equals(fieldName)) {
        //noinspection unchecked
        return true;
      }
    }
    return false;
  }

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

View on GitHub (pinned to 626827cddb)

Solutions

  1. Use HahaHelper.hasField(values, fieldName) first and handle the missing-field case explicitly
  2. Ensure the LeakCanary version analyzing the heap dump matches the version that captured it (same dependency on both sides)
  3. Keep ProGuard/R8 from renaming LeakCanary classes/fields: add keep rules for com.squareup.leakcanary.**

Example fix

// before
Object keyField = HahaHelper.fieldValue(values, "key");

// after
if (HahaHelper.hasField(values, "key")) {
  Object keyField = HahaHelper.fieldValue(values, "key");
} else {
  // heap dump produced by an incompatible LeakCanary version; skip
}
Defensive patterns

Strategy: validation

Validate before calling

if (HahaHelper.hasField(values, "key")) { Object keyField = HahaHelper.fieldValue(values, "key"); } else { /* incompatible dump: skip */ }

Try / catch

try { value = HahaHelper.fieldValue(values, name); } catch (IllegalArgumentException e) { // field absent: version skew or obfuscation; log and skip instance }

Prevention

When it happens

Trigger: Calling HahaHelper.fieldValue(values, fieldName) where the parsed ClassInstance has no field with that name. Concretely: looking up 'key' or 'referent' on an instance of a KeyedWeakReference class whose fields differ — i.e. the heap dump was produced by a different LeakCanary version than the one analyzing it, so the watched-reference class layout does not match.

Common situations: Version skew: an app shipped LeakCanary 1.5 (watcher field names/layout) but the analysis side (or DoraemonKit's bundled analyzer) expects a different layout. Renamed or obfuscated fields (ProGuard/R8 renaming the weak reference class fields). Analyzing a heap dump from another app.

Related errors


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