diff --git a/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HahaHelper.java b/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HahaHelper.java index bb09ad9211..b322c162ed 100644 --- a/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HahaHelper.java +++ b/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HahaHelper.java @@ -83,6 +83,7 @@ static String valueAsString(Object value) { /** Given a string instance from the heap dump, this returns its actual string value. */ static String asString(Object stringObject) { + checkNotNull(stringObject, "stringObject"); Instance instance = (Instance) stringObject; List values = classInstanceValues(instance); diff --git a/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HeapAnalyzer.java b/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HeapAnalyzer.java index d57663a534..ebd5617f6e 100644 --- a/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HeapAnalyzer.java +++ b/leakcanary-analyzer/src/main/java/com/squareup/leakcanary/HeapAnalyzer.java @@ -211,10 +211,19 @@ private String generateRootKey(RootObj root) { private Instance findLeakingReference(String key, Snapshot snapshot) { ClassObj refClass = snapshot.findClass(KeyedWeakReference.class.getName()); + if (refClass == null) { + throw new IllegalStateException( + "Could not find the " + KeyedWeakReference.class.getName() + " class in the heap dump."); + } List keysFound = new ArrayList<>(); for (Instance instance : refClass.getInstancesList()) { List values = classInstanceValues(instance); - String keyCandidate = asString(fieldValue(values, "key")); + Object keyFieldValue = fieldValue(values, "key"); + if (keyFieldValue == null) { + keysFound.add(null); + continue; + } + String keyCandidate = asString(keyFieldValue); if (keyCandidate.equals(key)) { return fieldValue(values, "referent"); } diff --git a/leakcanary-android/src/main/res/values/leak_canary_strings.xml b/leakcanary-android/src/main/res/values/leak_canary_strings.xml index b4faa52d09..e39f1f5390 100644 --- a/leakcanary-android/src/main/res/values/leak_canary_strings.xml +++ b/leakcanary-android/src/main/res/values/leak_canary_strings.xml @@ -34,7 +34,7 @@ Storage permission Dumping memory, app will freeze. Brrrr. Delete - "Please report this failure to http://github.com/square/leakcanary\n" + "Please report this failure to http://github.com/square/leakcanary and share the heapdump file that caused it.\n" Delete all Are you sure you want to delete all leaks? Could not save result.