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

Decoding of text/html data copied to Clipboard by Firefox under Linux fails

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_07"
      Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
      Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.6.24-19-generic #1 SMP Fri Jul 11 23:41:49 UTC 2008 i686 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Linux Ubuntu 8.04 run in VirtualBox 1.56

      A DESCRIPTION OF THE PROBLEM :
      Text/html content copied to clipboard by Firefox under Linux (ubuntu 8.04) is corrupted when it is read by Java (e.g. JRE 1.6.0_07) and can not be used. However text/html content copied by OpenOffice can be obtained without any problem.

      As a consequence java based rich text editors can not paste content from Firefox at all. Other editors like OpenOffice manage to handle such content too.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run Firefox and copy a text fragment into clipboard.

      Try to access it from java.awt.datatransfer.Transferable:

      Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable transferData = systemClipboard.getContents(null);
      DataFlavor htmlStringFlavor = new DataFlavor("text/html; class=java.lang.String");
      String content = (String) transferData.getTransferData(htmlStringFlavor);

      You can use the attached program which prints the data obtained from the clipboard to the standard output.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect correct encoded data.
      ACTUAL -
      Actually the String content has following data:

      (0) ? 65533
      (1) ? 65533
      (2) o 111
      (3) 0
      (4) u 117
      (5) 0
      (6) t 116
      (7) 0
      (8) p 112
      (9) 0
      (10) u 117
      (11) 0
      (12) t 116
      (13) 0


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Toolkit;
      import java.awt.datatransfer.Clipboard;
      import java.awt.datatransfer.DataFlavor;
      import java.awt.datatransfer.Transferable;

      class ClipboardPrinter
      {
        public static void main( String args[] ) throws Exception
        {
          Clipboard systemClipboard = Toolkit.getDefaultToolkit()
                                      .getSystemClipboard();
                      Transferable transferData = systemClipboard.getContents(null);
                      if (transferData == null) {
                              System.out.println("no content");
                              return;
                      }

                      // print encoded clipboard data as string
                      DataFlavor htmlStringFlavor = new DataFlavor(
                                      "text/html; class=java.lang.String");
                      if (!transferData.isDataFlavorSupported(htmlStringFlavor)) {
                              System.out.println("no text/html string content");
                              return;
                      }
                      String content = (String) transferData
                                      .getTransferData(htmlStringFlavor);

                      for (int i = 0; i < content.length(); i ++){
                              printlnCharacter(i, content.charAt(i));
                      }

                        System.out.println();
                        System.out.println(content);

        }

        private static void printlnCharacter(int i, final char c) {
                final int numericValue = c;
                System.out.print("(" + i + ")");
                System.out.print('\t');
                System.out.print(c == 0 || Character.isWhitespace(c) ? ' ' : c);
                System.out.print('\t');
                System.out.print(numericValue);
                System.out.println();
        }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              denis Denis Fokin (Inactive)
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: