From eddd963ca14debc314240b19ef5cd3f38a024018 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Thu, 22 Oct 2015 16:19:50 +0200 Subject: [PATCH] Fix exception in preprocessor Trying to run sketch with setup() without a body would crash the preprocessor. Now it gives correct error message. --- .../mode/java/preproc/PdePreprocessor.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/java/src/processing/mode/java/preproc/PdePreprocessor.java b/java/src/processing/mode/java/preproc/PdePreprocessor.java index 93be34ac6..f456cfa07 100644 --- a/java/src/processing/mode/java/preproc/PdePreprocessor.java +++ b/java/src/processing/mode/java/preproc/PdePreprocessor.java @@ -299,13 +299,14 @@ public class PdePreprocessor { MatchResult setupMatch = findInCurrentScope(VOID_SETUP_REGEX, uncommented); if (setupMatch != null) { int start = uncommented.indexOf("{", setupMatch.end()); - - // Find a closing brace - MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start); - if (match != null) { - searchArea = uncommented.substring(start + 1, match.end() - 1); - } else { - throw new SketchException("Found a { that's missing a matching }", false); + if (start >= 0) { + // Find a closing brace + MatchResult match = findInCurrentScope(CLOSING_BRACE, uncommented, start); + if (match != null) { + searchArea = uncommented.substring(start + 1, match.end() - 1); + } else { + throw new SketchException("Found a { that's missing a matching }", false); + } } } break;