From cee7c7aedfcb9dea5086f67795f9708289896b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Wed, 4 Dec 2024 08:48:30 +0100 Subject: [PATCH] Silent OperationCanceledException during hover #1827 If Operation is canceled result is just not needed anymore. No need to log an error. * also silent BadLocationException https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1827 --- .../jdt/internal/ui/text/java/hover/JavaSourceHover.java | 6 +++++- .../ui/org/eclipse/jdt/internal/ui/util/SelectionUtil.java | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java index d31910161b4..04528701c68 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaSourceHover.java @@ -613,7 +613,11 @@ private String getBracketHoverInfo(final ITextViewer textViewer, IRegion region) } return source; } catch (BadLocationException e) { - JavaPlugin.log(e); + /* + * This code runs in a separate thread which can + * lead to text offsets being out of bounds when + * computing the hover info (see bug 32848). + */ return null; } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/util/SelectionUtil.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/util/SelectionUtil.java index 0c82d9ed6a9..25dacce322e 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/util/SelectionUtil.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/util/SelectionUtil.java @@ -20,6 +20,7 @@ import java.util.Objects; import org.eclipse.core.runtime.ILog; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.resources.IResource; @@ -130,6 +131,12 @@ private SelectionUtil() { private static String lastErrorMsg; public static void logException(String action, RuntimeException e, String title, IDocument document, int offset) { + if (e instanceof OperationCanceledException ) { + // Be silent if operation is canceled see + // https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1827 + return; + } + // log error and keep going String errorMsg= e.getClass().getSimpleName() + " " + action; //$NON-NLS-1$ if (title != null) {