Skip to content

Commit

Permalink
fix(breadcrumb): Fix possible NPE in init without metadata (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali authored and fractalwrench committed Dec 19, 2019
1 parent 2bd45a8 commit 671db48
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
[#513](https://github.com/bugsnag/bugsnag-android/pull/513)
* Prevent overwrite of signal mask when installing ANR handler
[#520](https://github.com/bugsnag/bugsnag-android/pull/520)
* Fix possible null pointer exception when creating a breadcrumb without
metadata
[#585](https://github.com/bugsnag/bugsnag-android/pull/585)

## 4.21.1 (2019-10-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public final class Breadcrumb implements JsonStream.Streamable {
@NonNull BreadcrumbType type,
@NonNull Date captureDate,
@NonNull Map<String, String> metadata) {
if (captureDate == null) {
captureDate = new Date();
}
if (metadata == null) {
metadata = new HashMap<>();
}
this.timestamp = DateUtils.toIso8601(captureDate);
this.type = type;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.bugsnag.android;

import static org.junit.Assert.assertEquals;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Date;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class BreadcrumbNullabilityTest {

@Test
public void testCreateBreadcrumbWithoutMetadata() {
Breadcrumb crumb = new Breadcrumb("badger spotted", BreadcrumbType.USER, null);
assertEquals("badger spotted", crumb.getName());
assertEquals(BreadcrumbType.USER, crumb.getType());
assertEquals(0, crumb.getMetadata().size());
}

@Test
public void testCreateFullBreadcrumbWithoutMetadata() {
Breadcrumb crumb = new Breadcrumb("badger spotted", BreadcrumbType.USER, new Date(), null);
assertEquals("badger spotted", crumb.getName());
assertEquals(BreadcrumbType.USER, crumb.getType());
assertEquals(0, crumb.getMetadata().size());
}
}

0 comments on commit 671db48

Please sign in to comment.