commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r799910 - in /commons/proper/jexl/branches/2.0/src: java/org/apache/commons/jexl/scripting/JexlScriptEngine.java test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java
Date Sat, 01 Aug 2009 19:31:12 GMT
Author: sebb
Date: Sat Aug  1 19:31:11 2009
New Revision: 799910

URL: http://svn.apache.org/viewvc?rev=799910&view=rev
Log:
Script engine must throw NPE if either parameter is null

Modified:
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java
    commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java?rev=799910&r1=799909&r2=799910&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java
(original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java
Sat Aug  1 19:31:11 2009
@@ -75,6 +75,10 @@
 
     /** {@inheritDoc} */
     public Object eval(Reader script, ScriptContext context) throws ScriptException {
+        // This is mandated by JSR-223 (see SCR.5.5.2   Methods)
+        if (script == null || context == null) {
+            throw new NullPointerException("script and context must be non-null");
+        }
         BufferedReader reader = new BufferedReader(script);
         StringBuilder buffer = new StringBuilder();
         try {
@@ -98,8 +102,9 @@
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     public Object eval(String scriptText, final ScriptContext context) throws ScriptException
{
-        if (scriptText == null) {
-            return null;
+        // This is mandated by JSR-223 (see SCR.5.5.2   Methods)
+        if (scriptText == null || context == null) {
+            throw new NullPointerException("script and context must be non-null");
         }
         // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - Script Execution)
         context.setAttribute("context", context, ScriptContext.ENGINE_SCOPE);

Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java?rev=799910&r1=799909&r2=799910&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java
(original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java
Sat Aug  1 19:31:11 2009
@@ -18,10 +18,12 @@
 
 package org.apache.commons.jexl.scripting;
 
+import java.io.Reader;
 import java.util.Map;
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
 
 import junit.framework.TestCase;
 
@@ -50,6 +52,25 @@
         assertEquals(initialValue,engine.get("old"));
         assertEquals(newValue,engine.get("value"));
     }
+    
+    public void testNulls() throws Exception {
+        ScriptEngineManager manager = new ScriptEngineManager();
+        assertNotNull("Manager should not be null", manager);
+        ScriptEngine engine = manager.getEngineByName("jexl");
+        assertNotNull("Engine should not be null (name)", engine);
+        try {
+            engine.eval((String)null);
+            fail("Should have caused NPE");
+        } catch (NullPointerException e) {
+            // NOOP
+        }
+        try {
+            engine.eval((Reader)null);
+            fail("Should have caused NPE");
+        } catch (NullPointerException e) {
+            // NOOP
+        }
+    }
 
     public void testEngineNames() throws Exception {
         ScriptEngine engine;



Mime
View raw message