Site Sponsors:
Java Clipboard Woes on Ununtu 
Here is a classic tao of software testing - run it once, and the test passes. Right?

Well, by way of a VERY hard to find testing oversight, here is a bug under Java on Ubuntu. -The test works great the first time. Run the EXACT same test again and ... Boom! --Life suddenly gets mysterious:
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.io.StringReader;

/**
* CONCLUSION: CLIPBOARD ON UBUNTU RUNS FINE WHEN JAVA PROGRAM IS RUNNING. ERROR
* AFTER PROGRAM EXITS & CONTENT IS PASTED BACK INTO JAVA. Proof: Run this class
* twice - first time should run okay.The second time will fail. To clear the
* error, merely copy something ELSE to the clipboard.
*
* @author profnagy
*/
public class JaveClipboardWoes {
/*
Exception in thread "main" java.awt.datatransfer.UnsupportedFlavorException: Unicode String
at sun.awt.datatransfer.ClipboardTransferable.getTransferData(ClipboardTransferable.java:160)
at daily.newsletter._ClipboardWoes.main(_ClipboardWoes.java:32)
Java Result: 1
*/
public static void main_string() throws Exception {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor[] flavors = cb.getAvailableDataFlavors();
for (DataFlavor flav : flavors) {
System.out.println(flav.getMimeType());
}
// get whatever is on the clipboard
String str = (String) cb.getContents(null).getTransferData(DataFlavor.stringFlavor);
System.out.println(str);
// put a unicode string on the clipboard
StringSelection data = new StringSelection("Testing Is Important");
cb.setContents(data, data);
// get the unicode string okay!
System.out.println(cb.getContents(null).getTransferData(DataFlavor.stringFlavor));
}

/*
Exception in thread "main" java.awt.datatransfer.UnsupportedFlavorException: Plain Text
at sun.awt.datatransfer.ClipboardTransferable.getTransferData(ClipboardTransferable.java:160)
at daily.newsletter._ClipboardWoes.main(_ClipboardWoes.java:48)
Java Result: 1
*/
public static void main_text() throws Exception {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor[] flavors = cb.getAvailableDataFlavors();
for (DataFlavor flav : flavors) {
System.out.println(flav.getMimeType());
}
// get whatever is on the clipboard
StringReader str = (StringReader) cb.getContents(null).getTransferData(DataFlavor.plainTextFlavor);
System.out.println(str);
// put a unicode string on the clipboard
StringSelection data = new StringSelection("Important, testing is!");
cb.setContents(data, data);
// get the unicode string okay!
System.out.println(cb.getContents(null).getTransferData(DataFlavor.plainTextFlavor));
}

public static void main(String[] args) throws Exception {
main_text();
main_string();
main_text();
main_string();
}
}

While we are running Sun's JDK on Ubuntu 10.04, the problem has been reported elsewhere.

Software developers everywhere can probably relate to this happen-stance. While vexing, the fact that the problem has yet to be fixed - after 5 or so years of testing - should tell us allot?

Enjoy the Journey!



[ view entry ] ( 1637 views )   |  permalink

<<First <Back | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | Next> Last>>