matthiasblaesing commented on issue #3962: URL: https://github.com/apache/netbeans/issues/3962#issuecomment-1712184667
I'm late to the game, but I wondered why we don't see exception when this exceptional behavior occurs. I saw it at work (using Windows @work, never on Linux @home), but I still can not come up with the connecting element. Looking at the code in `NbClipboard` I see this: https://github.com/apache/netbeans/blob/f3bbe321592be090fe3c0a4ebf9a6107a3f69fcd/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java#L416-L443 Line 440/441 is a hard violation of the rule "Never catch an exception you are not prepared to handle". With https://github.com/apache/netbeans/pull/6428 / https://github.com/apache/netbeans/pull/6428/commits/19816a38da2b9f03adbfbc60184f730e7e8a259e I can get this stacktrace: ``` INFO [org.netbeans.NbClipboard]: systemClipboard not available (2) java.lang.IllegalStateException: cannot open system clipboard at java.desktop/sun.awt.windows.WClipboard.openClipboard(Native Method) at java.desktop/sun.awt.datatransfer.ClipboardTransferable.<init>(ClipboardTransferable.java:77) at java.desktop/sun.awt.datatransfer.SunClipboard.getContents(SunClipboard.java:138) [catch] at org.netbeans.NbClipboard$GetContents.run(NbClipboard.java:427) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1420) at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45) at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2035) ``` This looks like a source of the problem. To make this reproducible, I'm using this JNA code: ```java public class TestClipboard { public static void main(String[] args) throws Exception { System.out.println(User32Ex.INSTANCE.OpenClipboard(null)); try { Thread.sleep(10 * 1000); } finally { User32Ex.INSTANCE.CloseClipboard(); } } public static interface User32Ex extends User32 { User32Ex INSTANCE = Native.load("user32", User32Ex.class, W32APIOptions.DEFAULT_OPTIONS); boolean OpenClipboard(HWND hwndNewOwner); boolean CloseClipboard(); } } ``` Between the `OpenClipboard` and `CloseClipboard` calls no other application can access the windows clipboard. It was already established, that this might be a race condition and I suspect that in the cases users can reproduce the issue some other programm does something similar as NetBeans and blocks access to the clipboard. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
