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

added MAX_TRIES to SetContents of NbClipboard as well #8024

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,34 @@ private final class SetContents implements Runnable {
@Override
public void run() {
try {
systemClipboard.setContents(cnts, ownr);
} catch (IllegalStateException e) {
//#139616
if(log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "systemClipboard not available", e); // NOI18N
} else {
log.log(Level.INFO, "systemClipboard#setContents threw IllegalStateException"); // NOI18N
/* The loop will actually stop before getting to 10 iterations, per the delay
formula and conditional throw. But keep the MAX_TRIES just as a fail-safe. */
final int MAX_TRIES = 10;
final long start = System.currentTimeMillis();
int delay = 20;
for (int i = 0; i < MAX_TRIES; i++) {
try {
systemClipboard.setContents(cnts, ownr);
} catch (IllegalStateException ex) {
if (i == (MAX_TRIES - 1) || (System.currentTimeMillis() + delay - start) > 1000L) {
throw ex;
} else {
log.log(Level.INFO, "systemClipboard#getContents ISE, attempt {0}", i + 1); // NOI18N
Copy link
Contributor

Choose a reason for hiding this comment

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

Log message should say setContents instead of getContents here.

}
Thread.sleep(delay); // Give system time to settle
delay *= 2;
}
}
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "systemClipboard updated:"); // NOI18N
logFlavors(cnts, Level.FINE, log.isLoggable(Level.FINEST));
}
scheduleSetContents(cnts, ownr, 100);
return;
}
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "systemClipboard updated:"); // NOI18N
logFlavors(cnts, Level.FINE, log.isLoggable(Level.FINEST));
catch (ThreadDeath ex) {
throw ex;
}
catch (InterruptedException | RuntimeException ex) {
log.log(Level.INFO, "systemClipboard not available", ex); // NOI18N
}
}
}
Expand Down
Loading