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

"java.io.IOException: Owner failed to convert data" when pasting large data

XMLWordPrintable

    • x86
    • linux

      FULL PRODUCT VERSION :
      $ java -version
      java version "1.7.0"
      Java(TM) SE Runtime Environment (build 1.7.0-b147)
      Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      $ uname -a
      Linux 3.0.0-12-generic-pae #20-Ubuntu SMP Fri Oct 7 16:37:17 UTC 2011 i686 i686 i386 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      getReaderForText(transferable); code fails when the amount of data on the clipboard is large (> ~256kB):

      java.io.IOException: Owner failed to convert data



      The error seems evident in XSelection.java where dataGetter.dispose() is called before validateDataGetter(dataGetter); in the method getData(long format, long time):

      This happens only for incremental transfer which should explain the size dependency. This bug relates to several reported bugs with this issue that has been disregarded due to "Not reproducible" like Bug ID: 6936006.

      The error seems obvious...



      REGRESSION. Last worked in version 6u29

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the code below when there is a large amount of text on the clipboard (> 56 k)Code below fails when the amount of data on the clipboard is large (> ~256kB):



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Printout of text on clipboard

      ACTUAL -
      java.io.IOException: Owner failed to convert data

      ERROR MESSAGES/STACK TRACES THAT OCCUR :

      java.io.IOException: Owner failed to convert data
      at sun.awt.X11.XSelection.validateDataGetter(XSelection.java:444)
      at sun.awt.X11.XSelection.getData(XSelection.java:378)
      at sun.awt.X11.XClipboard.getClipboardData(XClipboard.java:120)
      at sun.awt.datatransfer.ClipboardTransferable.fetchOneFlavor(ClipboardTransferable.java:118)
      at sun.awt.datatransfer.ClipboardTransferable.<init>(ClipboardTransferable.java:97)
      at sun.awt.X11.XClipboard.getContents(XClipboard.java:106)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Toolkit;
      import java.awt.datatransfer.DataFlavor;
      import java.awt.datatransfer.Transferable;
      import java.io.LineNumberReader;
      import java.io.Reader;


      public class PasteTest {
      static private void paste() {
      Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
      DataFlavor [] availableFlavors = transferable.getTransferDataFlavors();
      DataFlavor selectedFlavor = DataFlavor.selectBestTextFlavor(availableFlavors);
      try {
      Reader reader = selectedFlavor.getReaderForText(transferable);

      LineNumberReader lnr = new LineNumberReader(reader);
      String line = lnr.readLine();
      while (line != null) {
      System.err.println(line);
      line = lnr.readLine();
      }
      } catch (Exception e) {
      e.printStackTrace();
      return;
      }
      }

      public static void main(String [] args) {
      paste();
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Workaround: Use java-6

        Fix: fix code in XSelection.java where, for incremental dataGetter.dispose() is called before validateDataGetter(dataGetter); in the method getData(long format, long time):

                         dataGetter.dispose();

                          ByteArrayOutputStream dataStream = new ByteArrayOutputStream(len);

                          while (true) {
                              WindowPropertyGetter incrDataGetter =
                                  new WindowPropertyGetter(XWindow.getXAWTRootWindow().getWindow(),
                                                           selectionPropertyAtom,
                                                           0, MAX_LENGTH, false,
                                                           XConstants.AnyPropertyType);

                              try {
                                  XToolkit.awtLock();
                                  XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
                                                              incrementalTransferHandler);

                                  propertyGetter = incrDataGetter;

                                  try {
                                      XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
                                                                  XWindow.getXAWTRootWindow().getWindow(),
                                                                  selectionPropertyAtom.getAtom());

                                      // If the owner doesn't respond within the
                                      // SELECTION_TIMEOUT, we terminate incremental
                                      // transfer.
                                      waitForSelectionNotify(incrDataGetter);
                                  } catch (InterruptedException ie) {
                                      break;
                                  } finally {
                                      propertyGetter = null;
                                      XToolkit.removeEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
                                                                     incrementalTransferHandler);
                                      XToolkit.awtUnlock();
                                  }

                                  validateDataGetter(dataGetter);

            denis Denis Fokin (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: