commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r429174 - in /jakarta/commons/proper/jexl/trunk/src: java/org/apache/commons/jexl/ScriptFactory.java test/org/apache/commons/jexl/ParseFailuresTest.java
Date Sun, 06 Aug 2006 18:55:35 GMT
Author: rahul
Date: Sun Aug  6 11:55:35 2006
New Revision: 429174

URL: http://svn.apache.org/viewvc?rev=429174&view=rev
Log:
Throw javacc Errors from ScriptFactory#createScript() methods as ParseExceptions.


Modified:
    jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
    jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/ParseFailuresTest.java

Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java?rev=429174&r1=429173&r2=429174&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
(original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
Sun Aug  6 11:55:35 2006
@@ -25,8 +25,10 @@
 import java.net.URLConnection;
 
 import org.apache.commons.jexl.parser.ASTJexlScript;
+import org.apache.commons.jexl.parser.ParseException;
 import org.apache.commons.jexl.parser.Parser;
 import org.apache.commons.jexl.parser.SimpleNode;
+import org.apache.commons.jexl.parser.TokenMgrError;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -155,7 +157,12 @@
         // Parse the Expression
         synchronized (parser) {
             log.debug("Parsing script: " + cleanText);
-            SimpleNode script = parser.parse(new StringReader(cleanText));
+            SimpleNode script;
+            try {
+                script = parser.parse(new StringReader(cleanText));
+            } catch (TokenMgrError tme) {
+                throw new ParseException(tme.getMessage());
+            }
             if (script instanceof ASTJexlScript) {
                 return new ScriptImpl(cleanText, (ASTJexlScript) script);
             } else {

Modified: jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/ParseFailuresTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/ParseFailuresTest.java?rev=429174&r1=429173&r2=429174&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/ParseFailuresTest.java
(original)
+++ jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/ParseFailuresTest.java
Sun Aug  6 11:55:35 2006
@@ -20,8 +20,9 @@
 import org.apache.commons.jexl.parser.ParseException;
 
 /**
- * Tests for malformed expressions.
- * ({@link ExpressionFactory} should throw {@link ParseException}s).
+ * Tests for malformed expressions and scripts.
+ * ({@link ExpressionFactory} and {@link ScriptFactory} should throw
+ * {@link ParseException}s).
  *
  * @since 1.1
  */
@@ -54,6 +55,43 @@
         try {
             Expression e = ExpressionFactory.createExpression(badExpression);
             fail("Parsing \"" + badExpression
+                + "\" should result in a ParseException");
+        } catch (ParseException pe) {
+            // expected
+        }
+    }
+
+    public void testMalformedScript1() throws Exception {
+        // this will throw a TokenMgrErr, which we rethrow as a ParseException
+        String badScript = "eq";
+        try {
+            Script s = ScriptFactory.createScript(badScript);
+            fail("Parsing \"" + badScript
+                + "\" should result in a ParseException");
+        } catch (ParseException pe) {
+            // expected
+        }
+    }
+
+
+    public void testMalformedScript2() throws Exception {
+        // this will throw a TokenMgrErr, which we rethrow as a ParseException
+        String badScript = "?";
+        try {
+            Script s = ScriptFactory.createScript(badScript);
+            fail("Parsing \"" + badScript
+                + "\" should result in a ParseException");
+        } catch (ParseException pe) {
+            // expected
+        }
+    }
+
+    public void testMalformedScript3() throws Exception {
+        // this will throw a TokenMgrErr, which we rethrow as a ParseException
+        String badScript = "foo=1;bar=2;a?b:c;";
+        try {
+            Script s = ScriptFactory.createScript(badScript);
+            fail("Parsing \"" + badScript
                 + "\" should result in a ParseException");
         } catch (ParseException pe) {
             // expected



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message