Name: sdR10048 Date: 06/27/2003
Filed By : SPB JCK team (###@###.###)
JDK : java full version "1.5.0-beta-b09"
JCK : 1.5
Platform[s] : Solaris
switch/Mode :
JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
Failing Test [s] :
api/java_awt/datatransfer/Clipboard/index.html#simple[Clipboard0006]
Specification excerpt:
======================
--------- J2SE API spec v.1.5 ---------
...
public void setContents(Transferable?contents,
ClipboardOwner?owner)
Sets the current contents of the clipboard to
the specified transferable object and registers
the specified clipboard owner as the owner of
the new contents.
If there is an existing owner registered, that owner
is notified that it no longer holds ownership of the
clipboard contents. The method throws IllegalStateException
if the clipboard is currently unavailable.
For example, on some platforms, the system clipboard is
unavailable while it is accessed by another application.
Parameters:
contents - the transferable object representing the clipboard content
owner - the object which owns the clipboard content
Throws:
IllegalStateException - if the clipboard is currently unavailable
...
---------- end-of-excerpt ---------------
Problem description
===================
Clipboard.setContent puts previous-owner notification in queue.
And as a result old owner can receive notification in some time after
the setContents method returns.
That has been moved in with CCC 4259272 implementation.
And that contradicts with current specification.
Asynchronous behavior should be specified explicitly.
See java.awt.Toolkit.prepareImage for example.
Minimized test:
===============
------- T.java -------
import java.awt.datatransfer.*;
public class T implements Transferable, ClipboardOwner {
// Transferable implementation
public Object getTransferData(DataFlavor flavor) {
return null;
}
public DataFlavor[] getTransferDataFlavors() {
return null;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return false;
}
// ClipboardOwner implementation
public boolean lostOwnershipCaught = false;
public void lostOwnership(Clipboard cb, Transferable t) {
lostOwnershipCaught = true;
}
// main
public static void main(String args[]) {
T transferable = new T();
T transferable2 = new T();
T cbOwner = new T();
T cbOwner2 = new T();
Clipboard cb = new Clipboard("Test");
cb.setContents(transferable,cbOwner);
cb.setContents(transferable2,cbOwner2);
/* COMMENTS TO REMOVE
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
System.out.println(e);
System.exit(0);
}
*/
if (cbOwner.lostOwnershipCaught) {
System.out.println("OK.");
} else {
System.out.println("setContents() does not invoke lostOwnership.");
}
}
}
------- end-of-T.java -------
Minimized test output (with commented Thread.sleep piece of code):
======================
] ~/tmp
] java T
setContents() does not invoke lostOwnership.
Output with uncommented Thread.sleep piece of code:
Minimized test output (with un-commented Thread.sleep piece of code):
======================
] ~/tmp
] java T
OK.
JCK test source location:
==========================
/java/re/jck/1.5/promoted/latest/JCK-runtime-15/tests
Test output (excerpt):
======================
...
Clipboard0006: Failed. setContents() does not invoke lostOwnership.
...
======================================================================