square / leakcanary

A memory leak detection library for Android.
https://square.github.io/leakcanary
Apache License 2.0
29.38k stars 3.97k forks source link

NPE in AndroidBuildMirror: Build class missing #2423

Open dvdface opened 2 years ago

dvdface commented 2 years ago

Description

use shark-cli-2.9.1 to analyze a heap dump throws kotlin.KotlinNullPointerException

Steps to Reproduce

[Provide a sample project, a .hprof file or a failing test]

1. shark-cli-2.9.1\bin>shark-cli.bat --hprof memory.dump analyze

====================================
HEAP ANALYSIS FAILED

You can report this failure at https://github.com/square/leakcanary/issues
Please provide the stacktrace, metadata and the heap dump file.
====================================
STACKTRACE

kotlin.KotlinNullPointerException
        at shark.AndroidBuildMirror$Companion$fromHeapGraph$1.invoke(AndroidBuildMirror.kt:28)
        at shark.AndroidBuildMirror$Companion$fromHeapGraph$1.invoke(AndroidBuildMirror.kt:22)
        at shark.GraphContext.getOrPut(GraphContext.kt:23)
        at shark.AndroidBuildMirror$Companion.fromHeapGraph(AndroidBuildMirror.kt:27)
        at shark.AndroidReferenceMatchers$Companion$libraryLeak$1.invoke(AndroidReferenceMatchers.kt:1404)
        at shark.AndroidReferenceMatchers$Companion$libraryLeak$1.invoke(AndroidReferenceMatchers.kt:1304)
        at shark.ReferenceMatcherKt.filterFor(ReferenceMatcher.kt:47)
        at shark.internal.ClassReferenceReader.<init>(ClassReferenceReader.kt:22)
        at shark.HeapAnalyzer.analyze(HeapAnalyzer.kt:154)
        at shark.HeapAnalyzer.analyze(HeapAnalyzer.kt:104)
        at shark.AnalyzeCommand$Companion.analyze(AnalyzeCommand.kt:36)
        at shark.AnalyzeCommand.run(AnalyzeCommand.kt:16)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:139)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:14)
        at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:215)
        at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:212)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:230)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:253)
        at shark.MainKt.main(Main.kt:12)
====================================
METADATA

Build.VERSION.SDK_INT: -1
Build.MANUFACTURER: Unknown
LeakCanary version: Unknown
Analysis duration: 0 ms
Heap dump file path: /mnt/d/Users/80362386/Desktop/shark-cli-2.9.1/bin/memory.dump
Heap dump timestamp: 1665194835108
====================================

I can't upload heap dump file, If you need , I can send to u by email.

Expected behavior: [What you expect to happen]

  1. run analysis normally without exception

Version Information

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

pyricau commented 1 year ago

The exception implies that we weren't able to find the android.os.Build class in the heap dump, which is surprising.

@dvdface Yes I'd love a heap dump: py.ricau at gmail

pyricau commented 1 year ago

Note: we should probably support the case of no Build class anyway, i.e. be able to run a JVM heap dump through shark-cli even if that yields nothing. Or at least error our "no build class, is this an Android heap dump?"