Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6296223

Spec violation: JavaScript engine (embedded in Sun's jdk) can throw not only ScriptException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • 6
    • 6
    • core-libs

      JavaScript engine (embedded in Sun's jdk) can throw not only ScriptException when script has a string that starts with valid operator(s) and ends with invalid one (see below example).
      This is a spec violation because spec for ScriptException class says clear:
      "The generic Exception class for the Scripting APIs. Checked exception types thrown by underlying scripting implementations must be wrapped in instances of ScriptException."

      Example:

      package test1;

      import javax.script.*;

      public class js_test {
          public static void main(String[] args) {
              String testScript = "print('Hello world');blabla;";
              ScriptEngineManager manager = new ScriptEngineManager();
              ScriptEngine jsFactory = manager.getEngineByExtension("js");
              try {
                  Object result = jsFactory.eval(testScript);
              } catch (ScriptException e) {
                  System.out.println("in ScriptException");
                  e.printStackTrace();
              } catch(Exception e) {
                  System.out.println("in Exception - bug present");
                  e.printStackTrace();
              }

          }
      }

      Above example will throw java.lang.ArrayIndexOutOfBoundsException, not ScriptException as spec required.
      ###@###.### 2005-07-13 09:44:14 GMT

            sundar Sundararajan Athijegannathan
            vsmelovsunw Vladimir Smelov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: