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

garbage characters appended to string value on return from javascript call

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6u23
    • Fix Version/s: 7u4
    • Component/s: deploy
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_23"
      OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.2)
      OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux ubuntu 3.0.0-16-generic #28-Ubuntu SMP Fri Jan 27 17:50:54 UTC 2012 i686 i686 i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      In javascript, if a string is less than 4 characters long, garbage characters will be appended to it when returned to Java.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open the attached html file in Chrome or Firefox.
      A Java applet will call several javascript functions and display return values in a table (both string value and hex-character dump)

      The problem can be reproduced using
      Chrome 17.0.963.56
      or
      Firefox 10.0.2

      Precompiled java applet and html code is available on this url:

      http://gs1.flyordie.com/linux-chrome-test/a.html


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Values ["", "1", "12","123", "1234", "12345", null] should appear in the first column of the table.
      ACTUAL -
      Instead of "", "1", "12" and "123" values with garbage characters appended will be displayed. Hex-dump shows character values fffd 62 53 fffd (or similar).

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      -------------------------------------- HTML code required for Applet

      <html>
      <body>
      <center>
      <script>
      function fn1(n) {
      return "";
      }
      function fn2(n) {
      return "1";
      }
      function fn3(n) {
      return "12";
      }
      function fn4(n) {
      return "123";
      }
      function fn5(n) {
      return "1234";
      }
      function fn6(n) {
      return "12345";
      }
      function fn7(n) {
      return null;
      }
      </script>
      <br>
      <object id="applet0" type="application/x-java-applet" width="500" height="210">
      <param name="code" value="A">
      <param name="scriptable" value="false">
      <param name="mayscript" value="true">
      <param name="fncnt" value="7">
      </object>
      </center>
      </body>
      </html>

      ------------------------------------- Applet code

      import java.awt.*;

      public class A extends java.applet.Applet implements Runnable {

      TextArea ta[];

      public void init() {
      String s = getParameter("fncnt");
      if(s == null)
      s = "3";
      ta = new TextArea[Integer.parseInt(s) * 2];
      setLayout(new GridLayout(ta.length / 2, 2));
      for(int i = 0; i < ta.length; i++) {
      TextArea t = ta[i] = new TextArea("", 1, 100, TextArea.SCROLLBARS_NONE);
      t.setEditable(false);
      add(t);
      }
      }

      public void start() {
      new Thread(this).start();
      }

      private void foo(int i, String fn) {
      try {
      Object r = netscape.javascript.JSObject.getWindow(this).call(fn, new Object[] { "dummy" });
      ta[i].setText(r == null ? "null": "\"" + r + '"');
      if(r != null) {
      String s = r.toString();
      StringBuilder sb = new StringBuilder();
      for(int j = 0; j < s.length(); j++)
      sb.append(' ').append(Integer.toHexString(s.charAt(j)));
      ta[i + 1].setText(sb.toString());
      }
      } catch(Exception e) {
      e.printStackTrace();
      ta[i].setText(e.toString());
      }
      }

      public void run() {
      for(int i = 0; i < ta.length; i += 2)
      foo(i, "fn" + ((i / 2) + 1));
      }
      }

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

        Attachments

          Activity

            People

            Assignee:
            henryjen Henry Jen
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: