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

JavaScript engine allows creation of interface although methods not available

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6u10
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b136
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_20"
      Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
      Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux porro 2.6.32-22-generic #36-Ubuntu SMP Thu Jun 3 22:02:19 UTC 2010 i686 GNU/Linux

      (Ubuntu Lucid system)

      A DESCRIPTION OF THE PROBLEM :
      The JavaDoc of javax.script.Invocable.getInterface(Class<T>) states:

      Returns:
          An instance of requested interface - null if the requested interface is unavailable, i. e. if compiled functions in the ScriptEngine cannot be found matching the ones in the requested interface.

      However, the JavaScript engine included in the Sun JRE always returns an interface object even if the necessary methods for the interface are not available. Only when invoking the methods a runtime exception is thrown.


      (There is no category in the bug system for the Java Scripting API, so the category of this bug is wrong.)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided test program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a=null instanceof=false
      Exception in thread "main" java.lang.NullPointerException
      at Testi.main(Testi.java:19)

      ACTUAL -
      a=[object Global] instanceof=true
      Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
      at $Proxy0.runA(Unknown Source)
      at Testi.main(Testi.java:19)
      Caused by: java.security.PrivilegedActionException: java.lang.NoSuchMethodException: no such method: runA
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.script.util.InterfaceImplementor$InterfaceImplementorInvocationHandler.invoke(InterfaceImplementor.java:49)
      ... 2 more
      Caused by: java.lang.NoSuchMethodException: no such method: runA
      at com.sun.script.javascript.RhinoScriptEngine.invoke(RhinoScriptEngine.java:170)
      at com.sun.script.javascript.RhinoScriptEngine.invokeFunction(RhinoScriptEngine.java:142)
      at com.sun.script.util.InterfaceImplementor$InterfaceImplementorInvocationHandler$1.run(InterfaceImplementor.java:52)
      ... 4 more


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.script.Invocable;
      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;

      public class Testi {

      public static void main(String[] args) throws Exception {
      ScriptEngineManager manager = new ScriptEngineManager();
      ScriptEngine engine = manager.getEngineByName("JavaScript");

      // No contents in the script, i.e. no functions defined
      engine.eval("");

      Invocable inv = (Invocable) engine;

      IntA a = inv.getInterface(IntA.class);

      System.out.println("a=" + a + " instanceof=" + (a instanceof IntA));
      a.runA();
      }
      }

      interface IntA {
      public void runA();
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't rely on script-interfaces working. Manually execute every method in the interface to test that it is executable.

        Attachments

          Activity

            People

            • Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: