From 47d8101ce89327ec0a2ed6e7abc19e092d627dc3 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Mon, 17 Dec 2018 15:21:36 +0100 Subject: [PATCH] Avoid NPE in onError --- client/src/main/java/ctbrec/ui/controls/StreamPreview.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/controls/StreamPreview.java b/client/src/main/java/ctbrec/ui/controls/StreamPreview.java index 2dd21c52..a7b5911f 100644 --- a/client/src/main/java/ctbrec/ui/controls/StreamPreview.java +++ b/client/src/main/java/ctbrec/ui/controls/StreamPreview.java @@ -3,6 +3,7 @@ package ctbrec.ui.controls; import java.io.InterruptedIOException; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -161,8 +162,9 @@ public class StreamPreview extends StackPane { private void onError(MediaPlayer videoPlayer) { LOG.error("Error while starting preview stream", videoPlayer.getError()); - if(videoPlayer.getError().getCause() != null) { - LOG.error("Error while starting preview stream root cause:", videoPlayer.getError().getCause()); + Optional cause = Optional.ofNullable(videoPlayer).map(v -> v.getError()).map(e -> e.getCause()); + if(cause.isPresent()) { + LOG.error("Error while starting preview stream root cause:", cause.get()); } showTestImage(); }