Skip to content

Commit

Permalink
Fix crash due to changed HashMap internals on API 25
Browse files Browse the repository at this point in the history
Fixes #2271
  • Loading branch information
pyricau committed Jan 6, 2022
1 parent 9f15c75 commit 8abde14
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ internal enum class OpenJdkInstanceRefReaders : OptionalFactory {
// Initially Entry, changed to Node in JDK 1.8
val nodeClassName = if (graph.findClassByName("java.util.HashMap\$Entry") != null) {
"java.util.HashMap\$Entry"
} else if (graph.findClassByName("java.util.HashMap\$HashMapEntry") != null) {
"java.util.HashMap\$HashMapEntry"
} else {
"java.util.HashMap\$Node"
}
Expand Down Expand Up @@ -172,6 +174,8 @@ internal enum class OpenJdkInstanceRefReaders : OptionalFactory {
// Initially Entry, changed to Node in JDK 1.8
val nodeClassName = if (graph.findClassByName("java.util.HashMap\$Entry") != null) {
"java.util.HashMap\$Entry"
} else if (graph.findClassByName("java.util.HashMap\$HashMapEntry") != null) {
"java.util.HashMap\$HashMapEntry"
} else {
"java.util.HashMap\$Node"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ class AndroidReferenceReadersHprofTest {
assertThat(mapReference.referenceName).isEqualTo("key()")
assertThat(mapReference.referenceType).isEqualTo(ARRAY_ENTRY)
}

@Test fun `API 25 HashMap$HashMapEntry supported`() {
val hprofFile = "hashmap_api_25.hprof".classpathFile()
val analysis = hprofFile.checkForLeaks<HeapAnalysisSuccess>()
val leakTrace = analysis.applicationLeaks.single().leakTraces.single()

val mapReference =
leakTrace.referencePath.single { it.owningClassSimpleName == "HashMap" }
assertThat(mapReference.referenceName).isEqualTo("leaking")
assertThat(mapReference.referenceType).isEqualTo(ARRAY_ENTRY)
}
}

fun String.classpathFile(): File {
Expand Down
Binary file added shark/src/test/resources/hashmap_api_25.hprof
Binary file not shown.

0 comments on commit 8abde14

Please sign in to comment.