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

Function to method resolution is broken

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Future Project
    • Affects Version/s: 6
    • Fix Version/s: 8-pool
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If a static method with the same name of an instance method is exposed, it is not possible to invoke it from script at all. This severely limits the ability to invoke Java methods from JavaScript.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the following program:

      package test;

      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;

      public class FunctionsClass {
         public static boolean xpto(Object arg1, Object arg2) {
            return equals(arg1, arg2);
         }
         
         public static boolean equals(Object arg1, Object arg2) {
            return arg1 == null ? arg2 == null : arg1.equals(arg2);
         }
         
         public static Object echo(Object o) {
            return o;
         }

         public static void main(String[] args) throws Exception {
            ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
            engine.put("f", new FunctionsClass());
            System.out.println(engine.eval("f.echo(f)"));
            System.out.println(engine.eval("f.xpto(null, null)"));
            System.out.println(engine.eval("f.equals('a', 'b')"));
         }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      test.FunctionsClass@14a9972
      true
      true
      ACTUAL -
      test.FunctionsClass@14a9972
      true
      Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method java.lang.Object.equals(string,string). (<Unknown source>#1) in <Unknown source> at line number 1
              at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
              at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
              at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
              at test.FunctionsClass.main(FunctionsClass.java:24)
      Java Result: 1

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Listed above on steps to reproduce
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Try to avoid the name clash or turn the method into an instance method if you control the class being exposed

        Attachments

          Activity

            People

            • Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: