Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry fetching clipboard contents when it initially fails #6443

Merged
merged 2 commits into from
Sep 23, 2023

Conversation

matthiasblaesing
Copy link
Contributor

It was reported, that clipboard copy/paste actions sometimes fail in
NetBeans (#3962). It was reported, that even with logging enabled no
exception was visible.

Clipboard#setContents and Clipboard#getContents are both documentent
that they can throw IllegalStateException when the clipboard can't be
accessed.

There are two changes here:

  1. If accessing the clipboard fails in GetContents#run, the exception will not
    be swallowed, but reported on level FINE (just as the rest of the logging)
  2. Access to the clipboard is retried, so that other programms blocking the
    clipboard don't interrupt all NetBeans copy operations.

@matthiasblaesing matthiasblaesing added DO NOT squash Platform [ci] enable platform tests (platform/*) UI User Interface ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Sep 13, 2023
@matthiasblaesing matthiasblaesing added this to the NB20 milestone Sep 13, 2023
@@ -437,7 +461,8 @@ public void run() {
catch (ThreadDeath ex) {
throw ex;
}
catch (Throwable ignore) {
catch (InterruptedException | RuntimeException ex) {
log.log(Level.FINE, "systemClipboard not available", ex); // NOI18N
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I'd do Level.INFO here, especially since we could here catch exceptions other than the known IllegalStateException from Clipboard.getContents.

// that is used because accessing the clipboard can block
// indefinitely. Running the access loop here is deemed similar
// in nature.
final int MAX_TRIES = 50;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to handle this issue differently in GetContents from SetContents? I think without good reason they should handle this in the same way, whether it be this way or that way being open to question.

https://github.com/apache/netbeans/blob/master/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java#L458

The pro and con of rescheduling rather than looping is that anything waiting on the task won't wait for the rescheduled one.

@matthiasblaesing
Copy link
Contributor Author

Pushed an update, that should address the concerns. I did not change the logic of SetContents vs. GetContents. In the GetContents case the Task that results from its instantiation is used to wait on it, I currently don't want to change the logic more.

@neilcsmith-net
Copy link
Member

As in at https://github.com/apache/netbeans/blob/master/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java#L198 ?

Makes sense to keep the distinction then, or at least GetContents as you have it (possibly with a comment). It could be worth considering the same change in SetContents. That task is also waited on in a few places, and I wonder if there is any point where that might be a problem.

@neilcsmith-net neilcsmith-net dismissed their stale review September 13, 2023 15:33

Distinction makes sense then.

@matthiasblaesing
Copy link
Contributor Author

So updated this with the timeout requested by @mbien. Shall we get this in?

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, looks good!

i think the other reviewers concerns were resolved too as far as I see but lets wait a bit for them to reply / close the comment threads

@eirikbakke
Copy link
Contributor

Thanks for the adjustments! Looks good!

@matthiasblaesing matthiasblaesing merged commit 3c33616 into apache:master Sep 23, 2023
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) DO NOT squash Platform [ci] enable platform tests (platform/*) UI User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants