Skip to content

Commit

Permalink
Merge pull request #540 from JLLeitschuh/fix/nullPointerInExceptionWi…
Browse files Browse the repository at this point in the history
…tness

Fixes Null Pointer from ExceptionWitnessResponderButton
  • Loading branch information
JLLeitschuh committed Apr 6, 2016
2 parents 88b8114 + 3426a01 commit fdf35cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ private synchronized ExceptionPopOver getPopover() {
final ExceptionPopOver newPopOver = new ExceptionPopOver(this.popOverTitle);
// Scene and root are null when the the constructor is called
// They are not null once they are added to a scene.
assert getScene() != null : "Scene should not be null, this object has not been added to the scene yet";
assert getScene().getRoot() != null : "Root should not be null, this object has not been added to the scene yet";
final Parent root = getScene().getRoot();
newPopOver.getRoot().getStylesheets().addAll(root.getStylesheets());
newPopOver.getRoot().setStyle(root.getStyle());
Expand All @@ -170,6 +172,10 @@ private synchronized ExceptionPopOver getPopover() {

@Subscribe
public void onExceptionEvent(ExceptionEvent event) {
if (getScene() == null || getScene().getRoot() == null) {
// We are responding to an event prior to this button being added to the scene. Ignore this for now.
return;
}
if (event.getOrigin().equals(origin)) {
// Not timing sensitive. Can remain Platform.runLater
Platform.runLater(() -> {
Expand All @@ -184,6 +190,10 @@ public void onExceptionEvent(ExceptionEvent event) {

@Subscribe
public void onExceptionClearedEvent(ExceptionClearedEvent event) {
if (getScene() == null || getScene().getRoot() == null) {
// We are responding to an event prior to this button being added to the scene. Ignore this for now.
return;
}
if (event.getOrigin().equals(origin)) {
// Not timing sensitive. Can remain Platform.runLater
Platform.runLater(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,19 @@ private void flagNewException() {

private void flagWarning() {
witness.flagWarning("A warning without a stacktrace");
}

@Test
public void testNoNullPointerBeforeAddedToScene() {
final EventBus eventBus = new EventBus();
final Object witnessed = new Object();
final ExceptionWitness witness = new MockExceptionWitness(eventBus, witnessed);

final ExceptionWitnessResponderButton button = new ExceptionWitnessResponderButton(witnessed, "Test Button Popover");
eventBus.register(button);
witness.flagWarning("Warning message");
witness.clearException();
// We should not get a null pointer because of any of this
}

}

0 comments on commit fdf35cb

Please sign in to comment.