-
Notifications
You must be signed in to change notification settings - Fork 34
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 #149 from bugsnag/fix-concurrent-modification-exc
Prevent potential ConcurrentModificationException when adding callback
- Loading branch information
Showing
4 changed files
with
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
sudo: required | ||
dist: trusty | ||
language: java | ||
before_cache: | ||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock | ||
|
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
44 changes: 44 additions & 0 deletions
44
bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java
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,44 @@ | ||
package com.bugsnag; | ||
|
||
import com.bugsnag.callbacks.Callback; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Ensures that if a callback is added or removed during iteration, a | ||
* {@link java.util.ConcurrentModificationException} is not thrown | ||
*/ | ||
public class ConcurrentCallbackTest { | ||
|
||
private Bugsnag bugsnag; | ||
|
||
@Before | ||
public void initBugsnag() { | ||
bugsnag = new Bugsnag("apikey"); | ||
} | ||
|
||
@After | ||
public void closeBugsnag() { | ||
bugsnag.close(); | ||
} | ||
|
||
@Test | ||
public void testClientNotifyModification() { | ||
final Configuration config = bugsnag.getConfig(); | ||
|
||
config.addCallback(new Callback() { | ||
@Override | ||
public void beforeNotify(Report report) { | ||
// modify the callback collection, when iterating to the next callback this should not crash | ||
config.addCallback(new Callback() { | ||
@Override | ||
public void beforeNotify(Report report) { | ||
} | ||
}); | ||
} | ||
}); | ||
bugsnag.notify(new RuntimeException()); | ||
} | ||
} |