Test that reproduces #1124
diff --git a/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/HeapAnalyzerHeapDumpTest.java b/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/HeapAnalyzerHeapDumpTest.java index d04c835..aa27fc3 100644 --- a/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/HeapAnalyzerHeapDumpTest.java +++ b/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/HeapAnalyzerHeapDumpTest.java
@@ -1,13 +1,25 @@ package com.squareup.leakcanary; +import com.squareup.haha.perflib.ClassObj; +import com.squareup.haha.perflib.HahaSpy; +import com.squareup.haha.perflib.Heap; +import com.squareup.haha.perflib.HprofParser; +import com.squareup.haha.perflib.Instance; +import com.squareup.haha.perflib.RootObj; +import com.squareup.haha.perflib.RootType; +import com.squareup.haha.perflib.Snapshot; +import com.squareup.haha.perflib.io.HprofBuffer; +import com.squareup.haha.perflib.io.MemoryMappedFileBuffer; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import static com.squareup.leakcanary.HahaHelper.threadName; import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK_M; import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK_PRE_M; import static com.squareup.leakcanary.TestUtil.HeapDumpFile.GC_ROOT_IN_NON_PRIMARY_HEAP; +import static com.squareup.leakcanary.TestUtil.HeapDumpFile.NOT_FOUND; import static com.squareup.leakcanary.TestUtil.analyze; import static com.squareup.leakcanary.TestUtil.findTrackedReferences; import static org.assertj.core.api.Assertions.assertThat; @@ -32,4 +44,11 @@ AnalysisResult result = analyze(GC_ROOT_IN_NON_PRIMARY_HEAP); assertThat(result.leakFound).isTrue(); } + + @Test public void heapdump_with_missing_thread_object() { + // To get this test to pass, set up a non suspending breakpoint in Heap.addThread that triggers + // on serialNumber == 1 and evaluates mThreads.put(2, thread). + AnalysisResult result = analyze(NOT_FOUND); + assertThat(result.leakFound).isTrue(); + } }
diff --git a/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/TestUtil.java b/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/TestUtil.java index 41ca942..2921e3f 100644 --- a/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/TestUtil.java +++ b/leakcanary-analyzer/src/test/java/com/squareup/leakcanary/TestUtil.java
@@ -29,6 +29,7 @@ enum HeapDumpFile { ASYNC_TASK_PRE_M("leak_asynctask_pre_m.hprof", "dc983a12-d029-4003-8890-7dd644c664c5"), // + NOT_FOUND("not_found.hprof", "c644e537-9abd-42e5-994d-032fc150feef"), // ASYNC_TASK_M("leak_asynctask_m.hprof", "25ae1778-7c1d-4ec7-ac50-5cce55424069"), // ASYNC_TASK_O("leak_asynctask_o.hprof", "0e8d40d7-8302-4493-93d5-962a4c176089"), GC_ROOT_IN_NON_PRIMARY_HEAP("gc_root_in_non_primary_heap.hprof",
diff --git a/leakcanary-analyzer/src/test/resources/not_found.hprof b/leakcanary-analyzer/src/test/resources/not_found.hprof new file mode 100644 index 0000000..4f37b45 --- /dev/null +++ b/leakcanary-analyzer/src/test/resources/not_found.hprof Binary files differ