apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.61k stars 836 forks source link

Paste within NetBeans editor only works on 2nd paste on macOS due to Pure Paste interaction #7126

Closed lannybroo closed 4 months ago

lannybroo commented 4 months ago

Apache NetBeans version

Apache NetBeans 21

What happened

What happens is that I copy some text from some of my Java source code in the NetBeans editor using ⌘ C (I'm on macOS Sonoma 14.3.1) then click somewhere else in the NetBeans editor and try to paste that code via ⌘ V. This first paste attempt fails every time. Nothing is pasted and the state of the editor window stays the same. If I watch carefully I see that the Edit menu does flash during this first paste as it does when running any keyboard command that is also in the menu in NetBeans. If I then try pasting a second time via ⌘ V, the paste succeeds. I can then paste over an over again and each subsequent paste succeeds until I copy something new.

What I expect to happen is for paste to always work.

The problem also occurs in the same way if you use the Edit > Copy then Edit > Paste menu commands instead of keyboard shortcuts.

The problem does not occur if you copy text from a different application (not NetBeans) and then paste into Netbeans. In this situation, the first paste into NetBeans succeeds.

I do not think this is related to existing open copy/paste issues such as #3962 or #5948.

Language / Project Type / NetBeans Component

No response

How to reproduce

  1. Copy some text in a NetBeans editor window
  2. Paste the text .. this first time won't work
  3. Paste the text again ... this time and later will work

Did this work correctly in an earlier version?

No / Don't know

Operating System

macOS Sonoma 14.3.1 on aarch64 (ARM M1 Mac)

JDK

11.0.17; OpenJDK 64-Bit Server VM 11.0.17+8-LTS (Zulu aarch64 JDK)

or

21.0.2; OpenJDK 64-Bit Server VM 21.0.2+13-LTS (Adoptium, aarch64 or 86 version of JDK)

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

This happens every time when copying from within NetBeans, as described above.

I'd be happy to help test/debug any fix ideas but I am too unfamiliar with this code base to work up a PR at this time.

I also grabbed a snip of an exception I see in View > IDE Log after the 2nd paste (that succeeds). Interesting I didn't see this exception after the 1st (failing) paste:

INFO [org.netbeans.modules.bugtracking.BugtrackingManager]: Loading stored repositories took 67 millis.
INFO [org.netbeans.ui.metrics.bugtracking]: USG_ISSUE_TRACKING_REPOSITORY
INFO [org.netbeans.NbClipboard]: System clipboard not available.
java.lang.SecurityException: All swing access to clipboard should be redirected to ExClipboard
    at org.netbeans.TopSecurityManager.checkWhetherAccessedFromSwingTransfer(TopSecurityManager.java:747)
    at org.netbeans.TopSecurityManager.checkPermission(TopSecurityManager.java:480)
    at java.desktop/sun.lwawt.LWToolkit.getSystemClipboard(LWToolkit.java:421)
    at java.desktop/sun.lwawt.macosx.CClipboard.notifyChanged(CClipboard.java:152)
    at java.desktop/sun.lwawt.macosx.CClipboard.checkPasteboardAndNotify(CClipboard.java:133)
    at java.desktop/sun.lwawt.macosx.CClipboard.getContents(CClipboard.java:61)
[catch] at org.netbeans.NbClipboard.getContents(NbClipboard.java:209)
    at java.desktop/javax.swing.TransferHandler$TransferAction.actionPerformedImpl(TransferHandler.java:1752)
    at java.desktop/javax.swing.TransferHandler$TransferAction$1.run(TransferHandler.java:1712)
    at java.desktop/javax.swing.TransferHandler$TransferAction$1.run(TransferHandler.java:1710)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/javax.swing.TransferHandler$TransferAction$2.run(TransferHandler.java:1727)
    at java.desktop/javax.swing.TransferHandler$TransferAction$2.run(TransferHandler.java:1725)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/javax.swing.TransferHandler$TransferAction.actionPerformed(TransferHandler.java:1724)
    at java.desktop/javax.swing.text.JTextComponent.invokeAction(JTextComponent.java:1523)
    at java.desktop/javax.swing.text.JTextComponent.paste(JTextComponent.java:1501)
    at org.netbeans.editor.BaseKit$PasteAction$1.run(BaseKit.java:2450)
    at org.netbeans.editor.GuardedDocument.runAtomicAsUser(GuardedDocument.java:333)
    at org.netbeans.editor.BaseKit$PasteAction.actionPerformed(BaseKit.java:2439)
    at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:324)
    at java.desktop/javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1810)
    at java.desktop/javax.swing.JComponent.processKeyBinding(JComponent.java:2900)
    at java.desktop/javax.swing.JComponent.processKeyBindings(JComponent.java:2948)
    at java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2862)
    at java.desktop/java.awt.Component.processEvent(Component.java:6412)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1950)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:870)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1139)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1009)
    at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:835)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4892)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:136)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Are you willing to submit a pull request?

No

lannybroo commented 4 months ago

Additional platform tests

On Linux x86 with Java 21 and NetBeans 21, this bug does not happen. On Linux x86 with Java 11 and NetBeans 21, this bug does not happen.

neilcsmith-net commented 4 months ago

Any chance you could try latest JDK 21, both aarch64 and amd64, on that Mac? Let's rule those variables out. The community installers have local Zulu 21 included if that's easier.

lannybroo commented 4 months ago

Any chance you could try latest JDK 21, both aarch64 and amd64, on that Mac? Let's rule those variables out. The community installers have local Zulu 21 included if that's easier.

I just now checked with Java JDK21 (Adoptium), and on both ARM (aarch64) and on Intel (amd64) JDKs I get the same problem. NetBeans runs fine otherwise.

neilcsmith-net commented 4 months ago

Thanks! I've just checked with my own macOS machine used for building and testing the installers. Currently also macOS Sonoma 14.3.1 on aarch64 (ARM M1 Mac)

I cannot replicate this problem using the community installer or the ASF installer, with JDK 21 (Zulu or Temurin respectively).

Have you tried starting with a clean userdir and cache? Locations visible in NetBeans / About NetBeans

lannybroo commented 4 months ago

I found the source of the problem. It was interference from the application Pure Paste which is a background application that removes formatting from the clipboard. When I quit Pure Paste or turn off its Automatically Clear Formatting setting, NetBeans paste behaves normally again. I'll write up an FYI to the Pure Paste developer.

I think this bug can be closed unless you think there is something to be learned by engaging further. Not sure if other clipboard management tools could also cause similar issues.