From f6e3581003738546238fb904863f81381675abfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Sat, 30 May 2026 18:04:34 +0200 Subject: [PATCH] fix: guard nullable workbench/page access before dereferencing Two UI helpers walked workbench.getActiveWorkbenchWindow().getActivePage()... chains with no null checks, NPEing when there is no active window/page/editor: - PlatformPluginAwareEditorOpener.open(): the page lookup was even outside the try, so the NPE escaped the IDE.openEditor error handling. Guard getActiveWorkbenchWindow() (matching the sibling getProjectName()); fall back to the super.open() result when null. - CheckHyperlinkHelper.createHyperlinksByOffset(): guard the whole chain (the injected workbench is optional and may be null) and the active editor before getEditorInput(); fall through to super when null. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../PlatformPluginAwareEditorOpener.java | 21 +++++++++++-------- .../ui/navigation/CheckHyperlinkHelper.java | 8 +++++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/editor/PlatformPluginAwareEditorOpener.java b/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/editor/PlatformPluginAwareEditorOpener.java index 8c694a8f2d..e483005d21 100644 --- a/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/editor/PlatformPluginAwareEditorOpener.java +++ b/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/editor/PlatformPluginAwareEditorOpener.java @@ -78,15 +78,18 @@ public IEditorPart open(final URI uri, final EReference crossReference, final in if (modelLocation != null) { PlatformPluginStorage storage = new PlatformPluginStorage(modelLocation); IEditorInput editorInput = new XtextReadonlyEditorInput(storage); - IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage(); - try { - IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID); - selectAndReveal(editor, uri, crossReference, indexInList, select); - return EditorUtils.getXtextEditor(editor); - } catch (WrappedException e) { - LOG.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (PartInitException partInitException) { - LOG.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); //$NON-NLS-1$ //$NON-NLS-2$ + final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); + if (activeWorkbenchWindow != null) { + IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); + try { + IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID); + selectAndReveal(editor, uri, crossReference, indexInList, select); + return EditorUtils.getXtextEditor(editor); + } catch (WrappedException e) { + LOG.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); //$NON-NLS-1$ //$NON-NLS-2$ + } catch (PartInitException partInitException) { + LOG.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); //$NON-NLS-1$ //$NON-NLS-2$ + } } } } diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/navigation/CheckHyperlinkHelper.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/navigation/CheckHyperlinkHelper.java index c3633e8a1a..9c48c37fd4 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/navigation/CheckHyperlinkHelper.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/navigation/CheckHyperlinkHelper.java @@ -13,6 +13,8 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.xtext.common.types.xtext.ui.TypeAwareHyperlinkHelper; import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.resource.EObjectAtOffsetHelper; @@ -39,8 +41,10 @@ public class CheckHyperlinkHelper extends TypeAwareHyperlinkHelper { @Override public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) { - IEditorPart activeEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); - if (activeEditor.getEditorInput() instanceof XtextReadonlyEditorInput) { + final IWorkbenchWindow activeWorkbenchWindow = workbench == null ? null : workbench.getActiveWorkbenchWindow(); + final IWorkbenchPage activePage = activeWorkbenchWindow == null ? null : activeWorkbenchWindow.getActivePage(); + final IEditorPart activeEditor = activePage == null ? null : activePage.getActiveEditor(); + if (activeEditor != null && activeEditor.getEditorInput() instanceof XtextReadonlyEditorInput) { INode crossRefNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(offset, 0)); if (crossRefNode == null) { return;