From 9156e4bd1b95d785991b3bcb8b0a156742e0c390 Mon Sep 17 00:00:00 2001 From: Thomas Johnson Date: Thu, 8 Nov 2018 10:55:55 -0600 Subject: [PATCH] fix possible NPE --- .../parser/TimeStampJSONParser.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java b/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java index 543f39d..67e2629 100644 --- a/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java +++ b/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java @@ -18,12 +18,25 @@ public TimeStampJSONParser(JsonObject transcript, String searchString) { OrderedJSONObject jsonObject = (OrderedJSONObject) transcript; + if(jsonObject == null) + return; + JSONArray monologues = (JSONArray) jsonObject.get("monologues"); - JSONObject speaker1 = (JSONObject) monologues.get(1); + if(monologues == null) + return; + + // TODO: Handle more than one speaker + JSONObject speaker = (JSONObject) monologues.get(0); - JSONArray elements = (JSONArray) speaker1.get("elements"); + if(speaker == null) + return; + + JSONArray elements = (JSONArray) speaker.get("elements"); + if(elements == null) + return; + String[] sentenceArray = searchString.split(" "); Double time = null; boolean done = false;