From d2b7c4f180c296b01f2a708b2cd627651713e769 Mon Sep 17 00:00:00 2001 From: bobpearson Date: Wed, 11 Jun 2014 13:39:06 -0500 Subject: [PATCH] Check if globals property found by Matcher A JsHint conf file might not necessarily have a globals property defined. The return of find() should be checked before proceeding to parse the results of matching. The current code generates an IllegalStateException if there is no globals section and group(1) is called. Optimally, a heavy-duty JSON parser lib (Jackson, GSON?) would be ideal, but I realize that is overkill for your project. Thanks! --- .../java/com/cj/jshintmojo/util/OptionsParser.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cj/jshintmojo/util/OptionsParser.java b/src/main/java/com/cj/jshintmojo/util/OptionsParser.java index 8974be2..abd6d6e 100644 --- a/src/main/java/com/cj/jshintmojo/util/OptionsParser.java +++ b/src/main/java/com/cj/jshintmojo/util/OptionsParser.java @@ -66,12 +66,12 @@ public static Set extractOptions(byte[] configFileContentsBytes) { public static Set extractGlobals(byte[] configFileContents) { String withoutComments = removeComments(new String(configFileContents)); Matcher matcher = GLOBALS_PATTERN.matcher(withoutComments); - matcher.find(); - String globalsCsv = matcher.group(1).replaceAll("\\s", "").replaceAll("\"", ""); - Set globalsSet = new HashSet(); - for (String global : globalsCsv.split(",")) { - globalsSet.add(global); + if (matcher.find()) { + String globalsCsv = matcher.group(1).replaceAll("\\s", "").replaceAll("\"", ""); + + for (String global : globalsCsv.split(",")) { + globalsSet.add(global); } return globalsSet; }