Skip to content

Commit

Permalink
Merge pull request #1056 from square/py/null_key
Browse files Browse the repository at this point in the history
Work around null KeyedWeakReference.key
  • Loading branch information
pyricau authored Jul 20, 2018
2 parents a62a6b9 + b172151 commit c425b82
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClassInstance.FieldValue> values = classInstanceValues(instance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> keysFound = new ArrayList<>();
for (Instance instance : refClass.getInstancesList()) {
List<ClassInstance.FieldValue> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<string name="leak_canary_storage_permission_activity_label">Storage permission</string>
<string name="leak_canary_toast_heap_dump">Dumping memory, app will freeze. Brrrr.</string>
<string name="leak_canary_delete">Delete</string>
<string name="leak_canary_failure_report">"Please report this failure to http://github.com/square/leakcanary\n"</string>
<string name="leak_canary_failure_report">"Please report this failure to http://github.com/square/leakcanary and share the heapdump file that caused it.\n"</string>
<string name="leak_canary_delete_all">Delete all</string>
<string name="leak_canary_delete_all_leaks_title">Are you sure you want to delete all leaks?</string>
<string name="leak_canary_could_not_save_title">Could not save result.</string>
Expand Down

0 comments on commit c425b82

Please sign in to comment.