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

nashorn object identity is compromised

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • None
    • core-libs
    • JDK8b132

    • generic
    • generic
    • Verified

      While investigating my #2 issue from
      https://bugs.openjdk.java.net/browse/JDK-8006183?focusedCommentId=13504584&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13504584
      I've noticed a problem with identity. I know the identity of Java objects passed to Nashorn and returned back is weaker than it used to be in Rhino - e.g. sometimes objects are not == only equal. But I found a case where the object is not even equal and I consider it a bug. Would you agree that following testIdentity function should never throw the IllegalStateException?

          public static void main(String[] args) throws Exception {
              ScriptEngineManager sem = new ScriptEngineManager();
              ScriptEngine eng = sem.getEngineByMimeType("text/javascript");
              Invocable inv = (Invocable) eng;

              testIdentity(eng, new Object());
              
          }
          
          private static void testIdentity(ScriptEngine eng, Object obj) throws Exception {
              Invocable inv = (Invocable) eng;

              eng.eval("function id(x) { return x; }");
              
              Object returned = inv.invokeFunction("id", obj);
              
              if (returned == obj || obj.equals(returned)) {
                  return;
              }
              throw new IllegalStateException(
                "Not equals! obj: " + obj + " returned: " + returned +
                "\ntypes: " + obj.getClass() + " real: " + returned.getClass()
              );
          }

      I would agree with such statement. Having a function that returns is parameter, should return the parameter. At least I hope.

            sundar Sundararajan Athijegannathan
            jtulach Jaroslav Tulach (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: