netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Problems with copy and paste in windows

Open andersonneto opened this issue 3 years ago • 241 comments

Apache NetBeans version

Apache NetBeans 13

What happened

This issue has been occurring in this version and earlier. Sometimes when we copy text from a website/browser on Windows operating system, Netbeans pastes information that was copied into Netbeans itself. And many times, I select from the website and drag it to Netbeans, to paste the text.

How to reproduce

The problem is only solved when I restart the application. Note: After presenting the problem, when a blank text is copied inside Netbeans, sometimes, when we copy a text externally, it manages to paste inside Netbeans. If pasted in any Windows environment, the text goes correctly, but within Netbeans, it copies the last information copied into the application.

Did this work correctly in an earlier version?

No

Operating System

Windows

JDK

16.0.2 (64bit)

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

Yes

Code of Conduct

Yes

andersonneto avatar Apr 11 '22 12:04 andersonneto

Unfortunately a long standing annoyance, which doesn't seem to have a definitive reproducible cause, or we know whether it's definitely NetBeans or the JDK at fault. Have a read of https://lists.apache.org/thread/xqkwy4wxylmzprxl1wko301hlqz59r7d and some of the flags, logging settings, etc. Be great to get to the bottom of this one!

neilcsmith-net avatar Apr 11 '22 12:04 neilcsmith-net

This is very annoying problem. I teach coding. Usually I code in a Google doc because it is live and students can follow along easily. When I want to compile my code I paste it into NetBeans. It fails and only pastes the last thing I copied from within Netbeans. Apparently the copy and paste works only within Netbeans. THIS IS A PROBLEM. Please fix!

The work around is to open the source file concurrently in a text editor and copy and paste there which updates the source file in Netbeans.

Montanajim avatar Apr 28 '22 01:04 Montanajim

@Montanajim if you have a reliable reproducer, then please share as much information as you can about environment, JDK, Windows version, browser you're pasting from, etc. Does it reproduce immediately, or after a time? Is it after a particular type of content has been added to the clipboard (from anywhere)? Do any of the suggestions in the linked thread above help? Is it NetBeans specific, or can you reproduce with other Java (Swing) applications?

It's well known that this is a problem, just not what the fix should actually be!

neilcsmith-net avatar Apr 28 '22 07:04 neilcsmith-net

I can reproduce the bug through these steps:

  1. Copy a piece of text in Netbeans
  2. Paste the text in an applicaiton
  3. In From this application copy some other text
  4. Paste the text into netbeans
  5. Paste it somewhere
  6. Copy text again
  7. Every new copy from netbeans from now on will not work anymore. If I do not copy in an outside application the clipboard will now be empty (and not the text from step 6 anymore)

I tested these steps with Notpad++, Firefox and the windows file explorer and have the same result exactly after these steps. Also if I mix applications in between. I checked the logs but no error was reported. I am running Netbeans 13 on Windows 10.0 on amd64 with Oracle JDK 17 (17+35-LTS-2724) but had the same issue on older JDKs.

If I can send you any log files or if I can help somehow please write me.

KKuehlem avatar Apr 29 '22 15:04 KKuehlem

This happens also in Windows 11 with AdoptOpenJDK 11 and Netbean zip distribution

NicolaIsotta avatar May 01 '22 18:05 NicolaIsotta

I have the same Problem. It occurs with any Apache Netbeans version (ranging from NB9 to NB15) and with every JDK Build on Windows that I have tested. This includes Java 8, 11 and 17 via Eclipse Temurin JDK, Azul Zulu JDK and some other JDK builds.

The bug occurs seemingly random.

Edit: Please see @epliskin's workaround as it also works consistently and does not require the extra plug-in from NB 7.1

I have found a workaround that works consistently:

Setup

  • Goto Tools -> Plugins (Tab: Settings)
  • Add the following Mirror: http://plugins.archive.librebeans.org/catalogue/7.1/catalog.xml and give it a name
  • Switch to Available Plugins and install the Plugin Copy and Paste History (Version 3.2.0 by Michel Graciano)
  • Restart Netbeans
  • Goto Tools -> Options -> Miscellaneous -> Copy and Paste History and check the box Replace Clipboard Content when pasting from history

Workaround

When the bug occurs, then press Alt+V in NB editor to open the clipboard history and insert any item from the menu that should have been opened by the plugin. Press Ctrl+Z to revert the insertion. The clipboard should work normally now.

Performing the Workaround before the bug occurs does not stop the bug from happening. Only performing the workaround after the bug occurs fixes the problem until the bug occurs again.

duoduobingbing avatar May 03 '22 12:05 duoduobingbing

Same issue with NB 13 and JDK 17. Doing a Control + c in netbeans and then control + v in netbeans works but control + v in another application doesn't work. In the other application stuff that was copied earlier is pasted (not the stuff that was copied most recently from NB). Reverse doesn't work either.

Doing empty Control+C (i.e. cntrl c without selecting any text) seems to reset this behavior. So, if ctrl v is not pasting the right stuff, do an empty ctrl c in netbeans and then select stuff and cntrl c to copy it. Now do ctrl v on another application to paste. It works.

Once it is pasted, then the problem resurfaces. So you have to do an empty cntrl c again to reset. Crazy.

pryshrm avatar May 16 '22 09:05 pryshrm

Same issue with NB12 and NB13 platform applications using JDK 11, 16, 17.

wumpz avatar May 17 '22 05:05 wumpz

I have the same problem. Windows OpenJdk 16.0.2.

the workaround by @duoduobingbing did not work the Copy and Paste History. The link is dead.

anyone have a workaround too ?

micky008 avatar Aug 22 '22 09:08 micky008

A naive attempt to fix: #4572

Also you may add the following command line option to netbeans.exe (or put it into netbeans.conf):

-J-Dnetbeans.slow.system.clipboard.hack=false

That'd switch off NetBeans Clipboard handling hacks which is enabled by default on all platforms save Mac.

Those hacks were introduced as a workaround for an AWT System clipboard issue around Java 5. They might be obsolete and causing issues now.

Please report back your experience either you are trying a build with the PR or testing the app with the provided flag!

lkishalmi avatar Sep 01 '22 01:09 lkishalmi

Testing the command line option with Netbeans 14 on Windows 11 and Java 11 The issue persists

NicolaIsotta avatar Sep 02 '22 15:09 NicolaIsotta

Thanks @NicolaIsotta Could you also try with -J-DTopSecurityManager.disable=true.

When you say it persists, is it immediate, or does it happen after some time? If after a time, is there anything you're doing that seems to be a common trigger? Is there anything that seems relevant in View / IDE Log around the time the problem starts occurring?

neilcsmith-net avatar Sep 02 '22 15:09 neilcsmith-net

Are you able to get a log of when it goes south. There discussion of this in

https://lists.apache.org/thread/nsg2pdzrs3go9f4zlhy0gjs2hfxmbdbn

But basically

Edit the netbeans.conf file in netbeans/etc/ to add:
 -J-Dorg.netbeans.NbClipboard.level=FINEST

errael avatar Sep 02 '22 15:09 errael

Also check with Java 17. This issue is on how Native Clipboard communicate with the JVM, so the JVM can count as well.

lkishalmi avatar Sep 02 '22 16:09 lkishalmi

Same issue with NetBeans 15, JDK 17, Windows. Based on duoduobingbing advice above the workaround is simply to open the built-in NetBeans clipboard history dialog with (Ctrl+Shift+D), select an item from history to paste into NetBeans editor and revert insertion with (Ctrl+Z). This magic revitalizes the NetBeans clipboard.

epliskin avatar Sep 13 '22 09:09 epliskin

It is so strange that we do not get feedback from the Windows folk running the IDE with -J-DTopSecurityManager.disable=true or -J-Dnetbeans.slow.system.clipboard.hack=false...

lkishalmi avatar Sep 20 '22 16:09 lkishalmi

-J-DTopSecurityManager.disable=true does not work for me at all, when I am using this option I cannot use the clipoard anywhere outside netbeans. -J-Dnetbeans.slow.system.clipboard.hack=false does work for me, if not combined with -J-DTopSecurityManager.disable=true. Still, I have to recopy text in netbeans to paste it somewhere else.

Besides, using the clipboard history, as mentioned by @epliskin , also works for me. (I am using Netbeans 14 on Oracle JDK 17)

KKuehlem avatar Sep 21 '22 07:09 KKuehlem

An hour ago I configured netbeans.conf with (-J-DTopSecurityManager.disable=true -J-Dorg.netbeans.NbClipboard.level=FINEST) and started NetBeans 15 with JDK 17. Clipboard works as yet fine between NetBeans and other Windows programs. At this time I do not edit any code eagerly but will report here in coming days or weeks if and when NetBeans clipboard freezes again...

epliskin avatar Sep 21 '22 07:09 epliskin

I wanted to thoroughly test before writing that this and that option definetely works or does not work; but here are my results after running with some options for a longer time:

  • -J-Dnetbeans.slow.system.clipboard.hack=false: The bug seemed to occur less frequently but it still occured.
  • -J-Dnetbeans.slow.system.clipboard.hack=false and -J-Dorg.netbeans.NbClipboard.level=FINEST: Seems to fix the issue. The bug did not occur once during using these.
  • -J-Dorg.netbeans.NbClipboard.level=FINEST: Seems to suffice. Have not used it as long as the others (less than one month) but the bug did not occur. Hopefully this is not tied to a race condition where org.netbeans.NbClipboard.level=FINEST fixes it for most people but not all.
  • -J-DTopSecurityManager.disable=true: Did not change anything. The bug still occured.
  • -J-DTopSecurityManager.disable=true and -J-Dorg.netbeans.NbClipboard.level=FINEST: The bug did not occur.

duoduobingbing avatar Sep 23 '22 13:09 duoduobingbing

See attached NetBeans log for this bug. I was editing some code when it happened. Could not paste from other Windows app, could not copy from NetBeans to another Windows app, but still could copy and paste text inside NetBeans editor.

netbeans_default_options = ... -J-DTopSecurityManager.disable=true -J-Dorg.netbeans.NbClipboard.level=FINEST

messages.zip

epliskin avatar Oct 04 '22 06:10 epliskin

And again some time after NetBeans restart...

messages2.zip

epliskin avatar Oct 04 '22 06:10 epliskin

I have the same problem with Netbeans 16, JDK 18. I have experienced the problem only in Java files so far, when I copy a text from pom.xml, for example, it works fine. Adding -J-Dorg.netbeans.NbClipboard.level=FINEST to netbeans.conf seems to fix the problem.

F-I-D-O avatar Dec 21 '22 10:12 F-I-D-O

I have the same problem with Netbeans 16, JDK 18. I have experienced the problem only in Java files so far, when I copy a text from pom.xml, for example, it works fine. Adding -J-Dorg.netbeans.NbClipboard.level=FINEST to netbeans.conf seems to fix the problem.

Yes. i confirm. it works.

micky008 avatar Dec 21 '22 11:12 micky008

Adding -J-Dorg.netbeans.NbClipboard.level=FINEST isn't a fix, and judging from @epliskin comments doesn't always mask the issue either. Enabling all the additional logging might be helping with a race condition, or maybe eagerly acquiring the transfer data in logFlavors() is helping - https://github.com/apache/netbeans/blob/master/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java#L288

neilcsmith-net avatar Dec 21 '22 12:12 neilcsmith-net

ha i've seen this problem since i started using netbeans v5. Still happens today. Seems more frequent of an issue with nb17 that in previous versions

spyhunter99 avatar Mar 10 '23 23:03 spyhunter99

Same issue with NB14, NB15, NB16, NB17 platform applications using JDK 11, 16, 17. This is very annoying. The most disturbing part is that all of our Netbeans Platform applications are affected.

Please address this issue. Most of the "hacks" do sometimes work but not always.

wumpz avatar Apr 04 '23 09:04 wumpz

Please address this issue. Most of the "hacks" do sometimes work but not always.

Then please help figure out what the cause of the issue is. If this issue was consistently reproducible or we knew what was causing it, it'd be fixed already!

neilcsmith-net avatar Apr 04 '23 09:04 neilcsmith-net

-J-Dnetbeans.slow.system.clipboard.hack=false seems to work for me. NB 17 and JDK 17.

wumpz avatar Apr 07 '23 19:04 wumpz

Where can this issue be upvoted? Because it is very annoying. A core functionality not working properly.

cquoss avatar May 03 '23 15:05 cquoss

@cquoss just try some of the suggestions above and report back if anything helps! Upvoting is pointless - we know it's an issue - we need to be able to replicate the problem, or know what is a reliable workaround, in order to be able to fix it.

neilcsmith-net avatar May 03 '23 15:05 neilcsmith-net