GitHub user xxDark added a comment to the discussion: Windows clipboard issues 
discussion

```
> Task :ClipboardTest.main()
AWT-Windows is running
AWT-Shutdown is running
AWT-EventQueue-0 is running
Exception "java.lang.ClassNotFoundException: 
com/intellij/codeInsight/editorActions/FoldingData"while constructing 
DataFlavor for: application/x-java-jvm-local-objectref; 
class=com.intellij.codeInsight.editorActions.FoldingData
Exception "java.lang.ClassNotFoundException: 
com/intellij/codeInsight/editorActions/FoldingData"while constructing 
DataFlavor for: application/x-java-jvm-local-objectref; 
class=com.intellij.codeInsight.editorActions.FoldingData
Exception "java.lang.ClassNotFoundException: 
com/intellij/codeInsight/editorActions/ReferenceData"while constructing 
DataFlavor for: application/x-java-jvm-local-objectref; 
class=com.intellij.codeInsight.editorActions.ReferenceData
Exception "java.lang.ClassNotFoundException: 
com/intellij/codeInsight/editorActions/ReferenceData"while constructing 
DataFlavor for: application/x-java-jvm-local-objectref; 
class=com.intellij.codeInsight.editorActions.ReferenceData
Exception "java.lang.ClassNotFoundException: 
com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData"while
 constructing DataFlavor for: application/x-java-serialized-object; 
class=com.intellij.openapi.editor.impl.EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData
Exception "java.lang.ClassNotFoundException: 
com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData"while
 constructing DataFlavor for: application/x-java-serialized-object; 
class=com.intellij.openapi.editor.impl.EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData
Ownership should've been lost (failed at 10 iterations)
```

```
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.util.UUID;

public class ClipboardTest {

        public static void main(String[] args) throws Exception {
                var clipboard = 
Toolkit.getDefaultToolkit().getSystemClipboard();
                // Comment out to "fix" the bug.
                clipboard.addFlavorListener(e -> {
                         //Dummy listener.
                });
                EventQueue.invokeLater(() -> {
                        // Dummy task.
                });
                for (var thread : Thread.getAllStackTraces().keySet()) {
                        var name = thread.getName();
                        if (name.contains("AWT")) {
                                System.out.printf("%s is running%n", name);
                        }
                }
                var r = new Runnable() {
                        final ClipboardContent content = new ClipboardContent();
                        State state = new State.SetContent();
                        int iteration;

                        @Override
                        public void run() {
                                try {
                                        switch (state) {
                                                case State.SetContent ignored 
-> {
                                                        var current = 
this.content;
                                                        var owner = 
current.owner;
                                                        owner.lost = false;
                                                        try {
                                                                
clipboard.setContents(current.selection, owner);
                                                        } catch 
(IllegalStateException ex) {
                                                                return;
                                                        }
                                                        state = new 
State.CheckOwnership(System.currentTimeMillis() + 5000L);
                                                }
                                                case State.CheckOwnership state 
-> {
                                                        if (content.owner.lost) 
{
                                                                // OK
                                                                this.state = 
new State.SetContent();
                                                                iteration++;
                                                        } else if 
(System.currentTimeMillis() > state.deadline) {
                                                                
System.err.printf("Ownership should've been lost (failed at %d iterations)%n", 
iteration);
                                                                
Runtime.getRuntime().halt(1);
                                                        }
                                                }
                                        }
                                } finally {
                                        EventQueue.invokeLater(this);
                                }
                        }
                };
                EventQueue.invokeLater(r);
                Thread.sleep(10000L);
                Runtime.getRuntime().halt(0);
        }

        private sealed interface State {

                record SetContent() implements State {
                }

                record CheckOwnership(long deadline) implements State {
                }
        }

        private static final class ClipboardContent {
                final OwnershipTracker owner = new OwnershipTracker();
                final String content = UUID.randomUUID().toString();
                final StringSelection selection = new StringSelection(content);
        }

        private static final class OwnershipTracker implements ClipboardOwner {
                volatile boolean lost;

                @Override
                public void lostOwnership(Clipboard clipboard, Transferable 
contents) {
                        lost = true;
                }
        }
}

```
While the test is running, hold Ctrl+C in NetBeans code area/IntelliJ
Comment out flavor listener setup, the issue will disappear

GitHub link: 
https://github.com/apache/netbeans/discussions/7051#discussioncomment-12764494

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: 
notifications-unsubscr...@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to