diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aacc5a7..ea088a41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Backtrace Android Release Notes +## Version 3.7.11 +- Fix NPE in DatabaseContext +- Add session attribute and backtrace reporter name to every error report + ## Version 3.7.10 - Add integration tests - Move common http response processing method to helper class diff --git a/backtrace-library/src/androidTest/java/backtraceio/library/database/BacktraceDatabaseContextTest.java b/backtrace-library/src/androidTest/java/backtraceio/library/database/BacktraceDatabaseContextTest.java index 7ff08a58..a05ce0b3 100644 --- a/backtrace-library/src/androidTest/java/backtraceio/library/database/BacktraceDatabaseContextTest.java +++ b/backtrace-library/src/androidTest/java/backtraceio/library/database/BacktraceDatabaseContextTest.java @@ -229,6 +229,16 @@ public void tryDeleteNotExistingRecordFromDatabaseContext() { assertEquals(3, databaseContext.count()); } + @Test(expected = NullPointerException.class) + public void tryAddNullBacktraceData() { + databaseContext.add((BacktraceData) null); + } + + @Test(expected = NullPointerException.class) + public void tryAddNullBacktraceDbRecord() { + databaseContext.add((BacktraceDatabaseRecord) null); + } + private List fillDatabase() { List result = new ArrayList<>(); BacktraceReport report = new BacktraceReport(this.testMessage); diff --git a/backtrace-library/src/main/java/backtraceio/library/services/BacktraceDatabaseContext.java b/backtrace-library/src/main/java/backtraceio/library/services/BacktraceDatabaseContext.java index b4a23861..e8274e69 100644 --- a/backtrace-library/src/main/java/backtraceio/library/services/BacktraceDatabaseContext.java +++ b/backtrace-library/src/main/java/backtraceio/library/services/BacktraceDatabaseContext.java @@ -72,7 +72,7 @@ public BacktraceDatabaseContext(Context context, BacktraceDatabaseSettings setti */ private BacktraceDatabaseContext(Context context, String path, int retryNumber, RetryOrder retryOrder) { this._applicationContext = context; - this._path = path;//this.getAbsolutePath(path); + this._path = path; this._retryNumber = retryNumber; this.retryOrder = retryOrder; setupBatch(); @@ -297,9 +297,9 @@ public boolean removeOldestRecord() { */ private void incrementBatches() { for (int i = this._retryNumber - 2; i >= 0; i--) { - List temp = this.batchRetry.get(i); + List currentBatch = this.batchRetry.get(i); batchRetry.put(i, new ArrayList()); - batchRetry.put(i + 1, temp); + batchRetry.put(i + 1, currentBatch); } } @@ -348,11 +348,17 @@ private BacktraceDatabaseRecord getLastRecord() { private BacktraceDatabaseRecord getRecordFromCache(boolean reverse) { for (int i = _retryNumber - 1; i >= 0; i--) { List reverseRecords = batchRetry.get(i); + + if (reverseRecords == null) { + continue; + } + if (reverse) { Collections.reverse(reverseRecords); } + for (BacktraceDatabaseRecord record : reverseRecords) { - if (!record.locked) { + if (record != null && !record.locked) { record.locked = true; return record; }