Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2022-02-15 16:17:05 +0000
committerAndrey Loskutov2022-02-16 16:32:03 +0000
commitfa43e50ed09d2684f9e2fd8cb6a24dbf43230525 (patch)
tree92c2f5b2e297f045a6c9b2dde00301284bd7249c
parent6b0c9ae07ac28cbbd1f8012b2c962f66820fa0b2 (diff)
downloadeclipse.platform.debug-fa43e50ed09d2684f9e2fd8cb6a24dbf43230525.tar.gz
eclipse.platform.debug-fa43e50ed09d2684f9e2fd8cb6a24dbf43230525.tar.xz
eclipse.platform.debug-fa43e50ed09d2684f9e2fd8cb6a24dbf43230525.zip
Bug 578760 - NPE and error dialog when "unexpected" editor type is
opened on breakpoint - Don't fail with NPE if editor doesn't have document provider installed. - Don't close previous editor if the same was opened by the page. - Try to reuse the editor if either the id OR the input are equal. This avoids closing & reopening same editor that was opened via "Large File Associations" preferences with different id. E.g. request to open a compilation unit editor for a file size > 8 MB will re-use already opened plain text editor, which has different editor id but is opened on same file input (and would not crash/hang). Change-Id: Ie8c9fd01aff356d1a2eff0b0d373026b391a29b2 Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.debug/+/190832 Reviewed-by: Simeon Andreev <simeon.danailov.andreev@gmail.com> Reviewed-by: Andrey Loskutov <loskutov@gmx.de> Tested-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/InstructionPointerManager.java4
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java31
2 files changed, 30 insertions, 5 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/InstructionPointerManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/InstructionPointerManager.java
index f5d1db073..42b1aab4e 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/InstructionPointerManager.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/InstructionPointerManager.java
@@ -92,8 +92,10 @@ public class InstructionPointerManager{
* specified stack frame.
*/
public void addAnnotation(ITextEditor textEditor, IStackFrame frame, Annotation annotation) {
-
IDocumentProvider docProvider = textEditor.getDocumentProvider();
+ if (docProvider == null) {
+ return;
+ }
IEditorInput editorInput = textEditor.getEditorInput();
// If there is no annotation model, there's nothing more to do
IAnnotationModel annModel = docProvider.getAnnotationModel(editorInput);
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java
index a3ee70ba9..c356da37e 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupFacility.java
@@ -69,6 +69,7 @@ import org.eclipse.ui.IReusableEditor;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.progress.UIJob;
@@ -467,7 +468,7 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro
// open a new editor
editor = openEditor(page, input, id);
editorForPage = editor;
- } else if (editorForPage instanceof IReusableEditor && editorForPage.getSite().getId().equals(id)) {
+ } else if (canReuseEditor(input, id, editorForPage)) {
// re-use editor
page.reuseEditor((IReusableEditor)editorForPage, input);
editor = editorForPage;
@@ -477,8 +478,10 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro
} else {
// close editor, open a new one
editor = openEditor(page, input, id);
- page.closeEditor(editorForPage, false);
- editorForPage = editor;
+ if (editor != editorForPage) {
+ page.closeEditor(editorForPage, false);
+ editorForPage = editor;
+ }
}
setEditor(page, editorForPage);
}
@@ -489,6 +492,22 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro
return editor;
}
+ private static boolean canReuseEditor(IEditorInput input, String id, IEditorPart editorForPage) {
+ if (!(editorForPage instanceof IReusableEditor)) {
+ return false;
+ }
+ IWorkbenchPartSite site = editorForPage.getSite();
+ if (site == null) {
+ // editor is disposed
+ return false;
+ }
+ if (site.getId().equals(id)) {
+ return true;
+ }
+ IEditorInput editorInput = editorForPage.getEditorInput();
+ return editorInput != null && input.equals(editorInput);
+ }
+
/**
* Positions the text editor for the given stack frame
*/
@@ -510,10 +529,14 @@ public class SourceLookupFacility implements IPageListener, IPartListener2, IPro
}
/**
- * Returns the line information for the given line in the given editor
+ * Returns the line information for the given line in the given editor, or
+ * {@code null} if no information could be retrieved or error happens
*/
private IRegion getLineInformation(ITextEditor editor, int lineNumber) {
IDocumentProvider provider= editor.getDocumentProvider();
+ if (provider == null) {
+ return null;
+ }
IEditorInput input= editor.getEditorInput();
try {
provider.connect(input);

Back to the top