Skip to content

Commit

Permalink
fix: prevent TimerTask errors from cancelling their Timer
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Nov 2, 2023
1 parent b79e85c commit 8a2c403
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,12 @@ private void startStopTimer() {
timer.schedule(new TimerTask() {
@Override
public void run() {
stop();
try {
stop();
} catch (Throwable t) {
//Need to catch time task exceptions, or it will cancel the timer
LOGGER.error("Failed to stop language server "+LanguageServerWrapper.this.serverDefinition.id, t);
}
}
}, TimeUnit.SECONDS.toMillis(this.serverDefinition.lastDocumentDisconnectedTimeout));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -35,6 +37,8 @@
*/
public class ClasspathResourceChangedNotifier implements Disposable {

private static final Logger LOGGER = LoggerFactory.getLogger(ClasspathResourceChangedNotifier.class);

private static final long DEBOUNCE_DELAY = 1000;

private final Project project;
Expand Down Expand Up @@ -80,7 +84,12 @@ private void asyncNotifyChanges() {
debounceTask = new TimerTask() {
@Override
public void run() {
notifyChanges();
try {
notifyChanges();
} catch (Throwable t) {
//Need to catch time task exceptions, or it will cancel the timer
LOGGER.error("Failed to notify classpath resource change", t);
}
}
};

Expand Down

0 comments on commit 8a2c403

Please sign in to comment.