You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2014/12/05 13:00:18 UTC

svn commit: r1643248 - in /sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl: compiler/frontend/SightlyParserErrorListener.java engine/UnitLoader.java

Author: fmeschbe
Date: Fri Dec  5 12:00:18 2014
New Revision: 1643248

URL: http://svn.apache.org/viewvc?rev=1643248&view=rev
Log:
SLING-4219  Prevent IllegalStateException if SlightlyParserErrorListener is called with null RecognitionException

Note: The actual problem is the SlingException(String, Throwable) constructor
   which calls initCause if the Throwable is null. This should be fixed as well.
   
(Applying patch by Radu Cotescu, thanks for providing the patch!)

Modified:
    sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/SightlyParserErrorListener.java
    sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/UnitLoader.java

Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/SightlyParserErrorListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/SightlyParserErrorListener.java?rev=1643248&r1=1643247&r2=1643248&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/SightlyParserErrorListener.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/SightlyParserErrorListener.java Fri Dec  5 12:00:18 2014
@@ -28,25 +28,22 @@ import org.antlr.v4.runtime.Parser;
 import org.antlr.v4.runtime.RecognitionException;
 import org.antlr.v4.runtime.Recognizer;
 import org.apache.sling.scripting.sightly.impl.compiler.SightlyParsingException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * The {@code SightlyParserErrorListener} handles parsing error reporting by sending offending input to a logger.
  */
 public class SightlyParserErrorListener extends BaseErrorListener {
 
-    private static final Logger LOG = LoggerFactory.getLogger(SightlyParserErrorListener.class);
-
     @Override
-    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
+    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg,
+                            RecognitionException e) {
         List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
         Collections.reverse(stack);
-        StringBuilder errorMessage = new StringBuilder();
-        errorMessage.append("Sightly syntax error detected.\n");
-        errorMessage.append("rule stack: ").append(stack).append("\n");
-        errorMessage.append("error starts at column: ").append(charPositionInLine).append("\n");
-        errorMessage.append(msg);
-        throw new SightlyParsingException("Sightly syntax error detected", ((CommonTokenStream) recognizer.getInputStream()).getTokenSource().getInputStream().toString(), e);
+        if (e != null) {
+            throw new SightlyParsingException(msg,
+                    ((CommonTokenStream) recognizer.getInputStream()).getTokenSource().getInputStream().toString(), e);
+        }
+        throw new SightlyParsingException(msg,
+                ((CommonTokenStream) recognizer.getInputStream()).getTokenSource().getInputStream().toString());
     }
 }

Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/UnitLoader.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/UnitLoader.java?rev=1643248&r1=1643247&r2=1643248&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/UnitLoader.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/UnitLoader.java Fri Dec  5 12:00:18 2014
@@ -292,7 +292,7 @@ public class UnitLoader implements Event
             if (StringUtils.isNotEmpty(offendingInput)) {
                 offendingInput = StringEscapeUtils.unescapeHtml(offendingInput.trim());
                 int errorLine = getLineWhereErrorOccurred(scriptSource, offendingInput);
-                throw new SightlyParsingException("Parsing error in template " + identifier.getResource().getPath() + " at line " +
+                throw new SightlyException("Parsing error in template " + identifier.getResource().getPath() + " at line " +
                         errorLine + ":\n" + offendingInput + "\n");
             } else {
                 throw e;