Skip to content

Commit 011008d

Browse files
committed
handle null nativeLibraryDir in TombstoneParser
1 parent f20587a commit 011008d

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/internal/tombstone/TombstoneParser.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public class TombstoneParser implements Closeable {
3030
private final InputStream tombstoneStream;
3131
@NotNull private final List<String> inAppIncludes;
3232
@NotNull private final List<String> inAppExcludes;
33-
// TODO: in theory can be null, but practically not for native crashes
34-
private final String nativeLibraryDir;
33+
@Nullable private final String nativeLibraryDir;
3534
private final Map<String, String> excTypeValueMap = new HashMap<>();
3635

3736
private static String formatHex(long value) {
@@ -42,7 +41,7 @@ public TombstoneParser(
4241
@NonNull final InputStream tombstoneStream,
4342
@NotNull List<String> inAppIncludes,
4443
@NotNull List<String> inAppExcludes,
45-
String nativeLibraryDir) {
44+
@Nullable String nativeLibraryDir) {
4645
this.tombstoneStream = tombstoneStream;
4746
this.inAppIncludes = inAppIncludes;
4847
this.inAppExcludes = inAppExcludes;
@@ -122,7 +121,9 @@ private SentryStackTrace createStackTrace(@NonNull final TombstoneProtos.Thread
122121
Boolean inApp =
123122
SentryStackTraceFactory.isInApp(frame.getFunctionName(), inAppIncludes, inAppExcludes);
124123

125-
inApp = (inApp != null && inApp) || frame.getFileName().startsWith(this.nativeLibraryDir);
124+
final boolean isInNativeLibraryDir =
125+
nativeLibraryDir != null && frame.getFileName().startsWith(nativeLibraryDir);
126+
inApp = (inApp != null && inApp) || isInNativeLibraryDir;
126127

127128
stackFrame.setInApp(inApp);
128129
frames.add(0, stackFrame);

sentry-android-core/src/test/java/io/sentry/android/core/internal/tombstone/TombstoneParserTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,26 @@ class TombstoneParserTest {
410410
assertEquals(expectedJson, actualJson)
411411
}
412412

413+
@Test
414+
fun `parses tombstone when nativeLibraryDir is null`() {
415+
val tombstoneStream =
416+
GZIPInputStream(TombstoneParserTest::class.java.getResourceAsStream("/tombstone.pb.gz"))
417+
val parser = TombstoneParser(tombstoneStream, inAppIncludes, inAppExcludes, null)
418+
val event = parser.parse()
419+
420+
// Parsing should succeed without NPE
421+
assertNotNull(event)
422+
assertEquals(62, event.threads!!.size)
423+
424+
// Without nativeLibraryDir, frames can only be marked inApp via inAppIncludes
425+
// All frames should still have inApp set (either true or false)
426+
for (thread in event.threads!!) {
427+
for (frame in thread.stacktrace!!.frames!!) {
428+
assertNotNull(frame.isInApp)
429+
}
430+
}
431+
}
432+
413433
private fun serializeDebugMeta(debugMeta: DebugMeta): String {
414434
val logger = mock<ILogger>()
415435
val writer = StringWriter()

0 commit comments

Comments
 (0)