-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0, 1.3.0
-
x86
-
windows_95, windows_98
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)
======================================================================
- duplicates
-
JDK-4289735 Unification of Clipboard and Drag & Drop Data Transfer
- Resolved