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

JavaScript to Java communication broken in 1.6.0_18 when using plugin2

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 6u18
    • deploy
    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      1.6.0_18

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

      A DESCRIPTION OF THE PROBLEM :
      In 1.6.0_18 when we call from JavaScript Java then JavaScript and then Java and then JavaScript...
      The last call of JSObject.call() do nothing. If we call not existent JavaScript function no exception is thrown at all.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Call from JavaScript a applet method1()
      2. Applet method1() calls JS function1() - this works fine
      3. JS function1 calls applet method2() - this works fine
      4. Applet metohd2() calls JS function2() - JS function is not called, no exception is thrown in applet.

      AppletTest.html:
      <html>
      <body>

      <script type="text/javascript">

          function test() {
              applet.method1();
          }

      function function1(value) {
              println(value);

      // Java method2() calls JavaScript function2() but it does not work
      applet.method2();

      // workaround is to call Java method2() in another 'context' like this:
      //setTimeout("applet.method2()", 0);
          }

      function function2(value) {
      // this method is not called
              println(value);
          }

          function println(text) {
           document.getElementById('text').value = document.getElementById('text').value + " " + text + "\n";
          }
      </script>

      <textarea id="text" rows="5" cols="20"></textarea>
      <input type="button" value="Test" onclick="alert('After test 'value1' and 'value2' should be printed in textArea');test()" /><br/>
      <applet codebase="." code="AppletTest.class" name="applet" width="100" height="100" MAYSCRIPT />

      </body>
      </html>


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      'value1' and 'value2' should be printed in HTML textarea
      ACTUAL -
      'value1'

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No exception is thrown at all (sholud be thrown)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      AppletTest.html:
      <html>
      <body>

      <script type="text/javascript">

          function test() {
              applet.method1();
          }

      function function1(value) {
              println(value);

      // Java method2() calls JavaScript function2() but it does not work
      applet.method2();

      // workaround is to call Java method2() in another 'context' like this:
      //setTimeout("applet.method2()", 0);
          }

      function function2(value) {
      // this method is not called
              println(value);
          }

          function println(text) {
           document.getElementById('text').value = document.getElementById('text').value + " " + text + "\n";
          }
      </script>

      <textarea id="text" rows="5" cols="20"></textarea>
      <input type="button" value="Test" onclick="alert('After test 'value1' and 'value2' should be printed in textArea');test()" /><br/>
      <applet codebase="." code="AppletTest.class" name="applet" width="100" height="100" MAYSCRIPT />

      </body>
      </html>

      AppletTest.java:
      import javax.swing.JApplet;

      import netscape.javascript.JSObject;

      public class AppletTest extends JApplet {

      public void method1() {
      System.out.println("Calling function1");
      JSObject win = (JSObject) JSObject.getWindow(this);
      win.call("function1", new Object[] { "value1" });
      }

      public void method2() {
      System.out.println("Calling function2");
      try {
                  JSObject win = (JSObject) JSObject.getWindow(this);

                  // this win.call(...) does not throw exception
                  // but JavaScript function2() is not called
                  win.call("function2", new Object[] { "value2" });

      // no exception is trown in 1.6.0_18 plugin2
              } catch (Exception e) {
                  e.printStackTrace();
              }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      call applet method2() in another 'context' like this:

      setTimeout("applet.method2()", 0);

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: