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

Applet does not return native JS string to JavsScript with Netscape/Firefox

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 5.0
    • deploy
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


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


      A DESCRIPTION OF THE PROBLEM :
      When the Java plug-in is used for applet support in Netscape 7.2 and Firefox 1.0.x, if JavaScript calls a method on an applet that returns a Java string, the returned object comes into JavaScript as a JavaObject, not a native JavaScript string. This causes problems with JavaScript that expects native strings to be returned from applets.

      This does *NOT* happen with Internet Explorer, even when Internet Explorer is using the plugin. Only with Netscape and Firefox (maybe Mozilla too, but I don't have that installed).


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      * Compile the SimpleApplet.java source included below.
      * Put the resulting .class file and the Applet.html file included
         below in the same directory.
      * Open Applet.html in Firefox or netscape.
      * Click on the "Click" link to run the JavaScript that will call
         into the applet.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect two alert boxes to pop up, one after the other.
      I would expect the first alert box to say:
         data = |Hello, world.|
      I would expect the second alert box to say:
         data.length = 13

      (and this is what I see when I run the example under IE)

      ACTUAL -
      I see the first alert box say
         data = |Hello, world.|
      But I see the second alert box say:
         data.length =
         function length() {
          [native code]
         }



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Applet code (save as SimpleApplet.java):
      import java.applet.Applet;

      public class SimpleApplet extends Applet {

          public void init() {
              log("initializing... ");
          }

          public void start() {
              log("starting... ");
          }

          public void stop() {
              log("stopping... ");
          }

          public void destroy() {
              log("preparing for unloading...");
          }

          public String getTheString() {
      return "Hello, world.";
          }

          void log(String message) {
              System.out.println(message);
          }
      }


      HTML page (save as Applet.html):
      <html>
         <body>
         <script language="JavaScript">

            function doStringStuff()
            {
               var data = document.testApplet.getTheString();
               alert("data = |" + data + "|");
               alert("data.length = " + data.length);
            }

         </script>

            This page demonstrates the Java-to-JavaScript string bug.
            <p>
            <applet name="testApplet" code="SimpleApplet.class"
                    width=1 height=1></applet>
            <a href="Applet.html" onClick="doStringStuff()">Click</a>
         </body>
      </html>

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

      CUSTOMER SUBMITTED WORKAROUND :
      Concatenate an empty javascript string to the object returned
      from the applet call.

      While that is trivial in one sense, it's not trivial if one is running
      a 3rd-party webapp where one has no access to any of the
      javascript in it.

            mleisunw Mike Lei (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: