You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2013/09/21 05:44:45 UTC

svn commit: r1525195 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/expressions/ lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java

Author: uschindler
Date: Sat Sep 21 03:44:44 2013
New Revision: 1525195

URL: http://svn.apache.org/r1525195
Log:
Merged revision(s) 1525194 from lucene/dev/trunk:
LUCENE-5207: Add a test that checks if the stack trace of an exception thrown from a Javascript function contains the original expression source code as the "filename".

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/expressions/   (props changed)
    lucene/dev/branches/branch_4x/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java

Modified: lucene/dev/branches/branch_4x/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java?rev=1525195&r1=1525194&r2=1525195&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java (original)
+++ lucene/dev/branches/branch_4x/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestCustomFunctions.java Sat Sep 21 03:44:44 2013
@@ -17,6 +17,8 @@ package org.apache.lucene.expressions.js
  * limitations under the License.
  */
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.HashMap;
@@ -233,4 +235,29 @@ public class TestCustomFunctions extends
       assertTrue(e.getMessage().contains("is not declared by a class which is accessible by the given parent ClassLoader"));
     }
   }
+  
+  static String MESSAGE = "This should not happen but it happens";
+  
+  public static class StaticThrowingException {
+    public static double method() { throw new ArithmeticException(MESSAGE); }
+  }
+  
+  /** the method throws an exception. We should check the stack trace that it contains the source code of the expression as file name. */
+  public void testThrowingException() throws Exception {
+    Map<String,Method> functions = new HashMap<String,Method>();
+    functions.put("foo", StaticThrowingException.class.getMethod("method"));
+    String source = "3 * foo() / 5";
+    Expression expr = JavascriptCompiler.compile(source, functions, getClass().getClassLoader());
+    try {
+      expr.evaluate(0, null);
+      fail();
+    } catch (ArithmeticException e) {
+      assertEquals(MESSAGE, e.getMessage());
+      StringWriter sw = new StringWriter();
+      PrintWriter pw = new PrintWriter(sw);
+      e.printStackTrace(pw);
+      pw.flush();
+      assertTrue(sw.toString().contains("JavascriptCompiler$CompiledExpression.evaluate(" + source + ")"));
+    }
+  }
 }