-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #534 from bugsnag/npe-minimal-err-fix
Fix NPE causing crash when reporting a minimal error
- Loading branch information
Showing
11 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...nner/src/main/java/com/bugsnag/android/mazerunner/scenarios/CorruptedOldReportScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:[email protected]:bugsnag/bugsnag-android.git | ||
|
22 changes: 22 additions & 0 deletions
22
...erunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/CorruptedReportScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\":[") } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/EmptyReportScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("") } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...src/main/java/com/bugsnag/android/mazerunner/scenarios/MinimalHandledExceptionScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...c/main/java/com/bugsnag/android/mazerunner/scenarios/MinimalUnhandledExceptionScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |