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

Clipboard failure for substring

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.2.0, 1.3.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_95, windows_98

      Description



      Name: dbT83986 Date: 02/19/99


      The following code snippet should put the string
      'xyz' into the clipboard. After running this program, pasting the clipboard's contents to a text editor, such as Microsoft NOTEPAD, pastes 'abc' instead of 'xyz'. Retrieving the string inside the same program from the Clipboard correctly gets 'xyz', though.
      This problem is caused by putting strings generated by a 'substring' function into the clipboard, the workaround, shown in the snippet, is to create a new string that doesn't involve a .substring call.
      This problem did not exist in 1.1

      public class bug
      {
      public static void main(String[] args)
      {
         Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
         String ms = "abcxyz";
         String text = ms.substring(3,6);
         // Uncomment next line for workaround:
         // text = new String(text);
         StringSelection contents = new StringSelection(text);
         clipboard.setContents(contents, contents);
      }
      }

      (Review ID: 47589)
      ======================================================================

      Name: yyT116575 Date: 01/09/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


      import java.awt.*;
      import java.awt.datatransfer.*;

      /** the following code should paste "is a test." to the clipboard.
           instead, it pastes "this is a"
      */
      public class SelectionBug implements ClipboardOwner {
        public static void main(String[] args) {
          new SelectionBug();
        }
        public SelectionBug() {
          Frame f=new Frame();
          Clipboard clipboard=f.getToolkit().getSystemClipboard();
          String str="this is a test.";
          StringSelection contents=new StringSelection(str.substring(5));
          clipboard.setContents(contents, SelectionBug.this);
        }
        public void lostOwnership(Clipboard c, Transferable t) {}
      }
      (Review ID: 114618)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dmendenhsunw David Mendenhall (Inactive)
              Reporter:
              dblairsunw Dave Blair (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: