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

AssertionError: __noSuchProperty__ placeholder called from NativeJavaImporter

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u40, 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b36
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        This bug is reported from this blog entry and the discussion followed from it:

        http://blog.tempusdictum.com/index.php/gepr/java-8-nashorn-problem

        File: Eval.java

        import java.io.FileNotFoundException;
        import java.io.IOException;
        import javax.script.ScriptException;

        public class Eval {
          final static javax.script.ScriptEngineManager manager = new javax.script.ScriptEngineManager();
          final static javax.script.ScriptEngine engine = manager.getEngineByExtension("js");
          javax.script.ScriptContext context = new javax.script.SimpleScriptContext();
          public javax.script.Bindings scope = null;

          String script = null;

          public Eval(String fileName) {
            context.setBindings(engine.createBindings(), javax.script.ScriptContext.ENGINE_SCOPE);
            scope = context.getBindings(javax.script.ScriptContext.ENGINE_SCOPE);

            script = convertStreamToString(
                     getClass().getClassLoader().getResourceAsStream(fileName));
          }

          public static String convertStreamToString(java.io.InputStream is) {
            java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
            return s.hasNext() ? s.next() : "";
          }

          public double eval(double t) {
            double retVal = Double.NaN;
            Object result = null;
            scope.put("ind", t);
            try {
              result = engine.eval(script,scope);
            } catch (ScriptException e) {
              System.err.println(e.getMessage());
              e.printStackTrace();
              System.exit(-1);
            }
            if (result instanceof Double)
              retVal = (Double)result;
            else
              retVal = ((Integer)result).doubleValue();
            return retVal;
          }

          public static void main(String args[]) {
            Eval se1 = null;
            Eval se2 = null;
            se1 = new Eval("test.js");
            se2 = new Eval("test.js");
            se1.scope.put("constant", 1.00);
            se2.scope.put("constant", 0.50);
            for (double t=0.0; t<150.0; t += 10.0) {
              System.out.print("test eval("+t+") = "+ se1.eval(t)+" : ");
              System.out.println("test eval("+t+") = "+ se2.eval(t));
            }
          }
        }


        File: test.js

        var math = new JavaImporter(java.lang.StrictMath);
        var constant;
        var ind;
        with (math) {
          tempy = StrictMath.exp(-constant*ind);
        }

        Commands:

        $ javac Eval.java
        $ java -Djava.ext.dirs=<nashorn.jar-dir-from-jdk9-or-jdk8u-dev> Eval


        test eval(0.0) = 1.0 : test eval(0.0) = 1.0
        test eval(10.0) = 4.539992976248485E-5 : test eval(10.0) = 0.006737946999085467
        test eval(20.0) = 2.061153622438558E-9 : test eval(20.0) = 4.539992976248485E-5
        test eval(30.0) = 9.357622968840175E-14 : test eval(30.0) = 3.059023205018258E-7
        test eval(40.0) = 4.248354255291589E-18 : test eval(40.0) = 2.061153622438558E-9
        test eval(50.0) = 1.9287498479639178E-22 : test eval(50.0) = 1.3887943864964021E-11
        test eval(60.0) = 8.75651076269652E-27 : test eval(60.0) = 9.357622968840175E-14
        test eval(70.0) = 3.975449735908647E-31 : test eval(70.0) = 6.305116760146989E-16
        test eval(80.0) = 1.804851387845415E-35 : test eval(80.0) = 4.248354255291589E-18
        test eval(90.0) = 8.194012623990515E-40 : Exception in thread "main" java.lang.AssertionError: __noSuchProperty__ placeholder called
        at jdk.nashorn.internal.objects.NativeJavaImporter.__noSuchProperty__(NativeJavaImporter.java:108)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:658)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
        at jdk.nashorn.internal.runtime.ScriptObject.invokeNoSuchProperty(ScriptObject.java:2378)
        at jdk.nashorn.internal.runtime.ScriptObject.megamorphicGet(ScriptObject.java:2043)
        at jdk.nashorn.internal.scripts.Script$Recompilation$3$\^eval\_.:program(<eval>:5)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:636)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:459)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:423)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:419)
        at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:152)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
        at Eval.eval(Eval.java:31)
        at Eval.main(Eval.java:53)

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                sundar Sundararajan Athijegannathan
                Reporter:
                sundar Sundararajan Athijegannathan
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: