Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE causing crash when reporting a minimal error #534

Merged
merged 5 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.17.1 (2019-07-24)

### Bug fixes
* Fix NPE causing crash when reporting a minimal error
[#534](https://github.com/bugsnag/bugsnag-android/pull/534)

## 4.17.0 (2019-07-17)

This release modularizes `bugsnag-android` into 3 separate artifacts: for JVM (Core), NDK, and ANR error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ private void flushErrorReport(File errorFile) {
} catch (Exception exception) {
if (delegate != null) {
Error minimalError = generateErrorFromFilename(errorFile.getName());
delegate.onErrorReadFailure(minimalError);

if (minimalError != null) {
delegate.onErrorReadFailure(minimalError);
}
}
deleteStoredFiles(Collections.singleton(errorFile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class Notifier implements JsonStream.Streamable {

private static final String NOTIFIER_NAME = "Android Bugsnag Notifier";
private static final String NOTIFIER_VERSION = "4.17.0";
private static final String NOTIFIER_VERSION = "4.17.1";
private static final String NOTIFIER_URL = "https://bugsnag.com";

@NonNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import java.io.File

/**
* Verifies that if a report is corrupted with an old filename,
* Bugsnag does not crash.
*/
internal class CorruptedOldReportScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)
val files = File(context.cacheDir, "bugsnag-errors").listFiles()

// create an empty (invalid) file with an old name
files.forEach {
val dir = File(it.parent)
it.writeText("{\"exceptions\":[{\"stacktrace\":[")
it.renameTo(File(dir, "1504255147933_683c6b92-b325-4987-80ad-77086509ca1e.json"))
}
}

override fun run() {
super.run()
Bugsnag.notify(generateException())
}
}
9 changes: 9 additions & 0 deletions features/minimal_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ Scenario: Minimal error report for an Unhandled Exception with a corrupted file
And the event "unhandled" is true
And the event "incomplete" is true
And the event "severityReason.type" equals "unhandledException"

Scenario: Minimal error report with old filename
When I run "MinimalUnhandledExceptionScenario"
And I set environment variable "EVENT_TYPE" to "CorruptedOldReportScenario"
And I relaunch the app
Then I should receive 1 request
And the request is valid for the error reporting API
And the event "unhandled" is false
And the event "incomplete" is false
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=4.17.0
VERSION_NAME=4.17.1
GROUP=com.bugsnag
POM_SCM_URL=https://github.com/bugsnag/bugsnag-android
POM_SCM_CONNECTION=scm:git@github.com:bugsnag/bugsnag-android.git
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import java.io.File

/**
* Verifies that if a report is corrupted, minimal information is still sent to bugsnag.
*/
internal class CorruptedReportScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)
val files = File(context.cacheDir, "bugsnag-errors").listFiles()
files.forEach { it.writeText("{\"exceptions\":[{\"stacktrace\":[") }

val nativeFiles = File(context.cacheDir, "bugsnag-native").listFiles()
nativeFiles.forEach { it.writeText("{\"exceptions\":[{\"stacktrace\":[") }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import java.io.File

/**
* Verifies that if a report is empty, minimal information is still sent to bugsnag.
*/
internal class EmptyReportScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)
val files = File(context.cacheDir, "bugsnag-errors").listFiles()
files.forEach { it.writeText("") }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import java.io.File

/**
* Sends a handled exception to Bugsnag, which does not include session data.
*/
internal class MinimalHandledExceptionScenario(config: Configuration,
context: Context) : Scenario(config, context) {

init {
config.setAutoCaptureSessions(false)
disableAllDelivery(config)
}

override fun run() {
super.run()
Bugsnag.notify(java.lang.RuntimeException("Whoops"))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Configuration
import java.io.File

/**
* Sends an unhandled exception to Bugsnag.
*/
internal class MinimalUnhandledExceptionScenario(config: Configuration,
context: Context) : Scenario(config, context) {
init {
config.setAutoCaptureSessions(false)
disableAllDelivery(config)
}

override fun run() {
super.run()
throw java.lang.IllegalStateException("Whoops")
}

}
25 changes: 25 additions & 0 deletions tests/features/minimal_report.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Minimal error information is reported for corrupted/empty files

Scenario: Minimal error report for a Handled Exception with an empty file
When I run "MinimalHandledExceptionScenario" and relaunch the app
And I configure Bugsnag for "EmptyReportScenario"
And I wait to receive a request
And the request is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the payload field "events.0.exceptions.0.stacktrace" is an array with 0 elements
And the exception "errorClass" equals "java.lang.RuntimeException"
And the event "severity" equals "warning"
And the event "unhandled" is false
And the event "incomplete" is true
And the event "severityReason.type" equals "handledException"

Scenario: Minimal error report for an Unhandled Exception with a corrupted file
When I run "MinimalUnhandledExceptionScenario" and relaunch the app
And I configure Bugsnag for "CorruptedReportScenario"
And I wait to receive a request
And the request is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the payload field "events.0.exceptions.0.stacktrace" is an array with 0 elements
And the exception "errorClass" equals "java.lang.IllegalStateException"
And the event "severity" equals "error"
And the event "unhandled" is true
And the event "incomplete" is true
And the event "severityReason.type" equals "unhandledException"