Skip to content

Commit

Permalink
Avoid FindReplaceOverlay setTextEditorActionsActivated resulting in NPE
Browse files Browse the repository at this point in the history
- The FindReplaceOverlay's setTextEditorActionsActivated method
reflectively invokes AbstractTextEditor.setActionActivation(boolean) and
that method assumes that getEditorSite().getActionBarContributor()
returns non-null but MultiPageEditorSite.getActionBarContributor()
returns null so in PDE's target editor, this leads to an NPE.
- AbstractTextEditor.setActionActivation(boolean) must guard against a
null action contributor to avoid NPE
- The logic in setTextEditorActionsActivated already has special case
handling for MultiPageEditorSite which should be augmented to call
IEditorActionBarContributor.setActiveEditor(IEditorPart) on the overall
multi-page editor.
  • Loading branch information
merks committed Jan 17, 2025
1 parent dbf808e commit aa689b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.eclipse.jface.text.ITextViewer;

import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
Expand All @@ -73,6 +74,7 @@
import org.eclipse.ui.internal.findandreplace.HistoryStore;
import org.eclipse.ui.internal.findandreplace.SearchOptions;
import org.eclipse.ui.internal.texteditor.TextEditorPlugin;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.MultiPageEditorSite;

import org.eclipse.ui.texteditor.AbstractTextEditor;
Expand Down Expand Up @@ -177,11 +179,21 @@ private void setTextEditorActionsActivated(boolean state) {
return;
}
if (targetPart.getSite() instanceof MultiPageEditorSite multiEditorSite) {
IEditorActionBarContributor actionBarContributor = multiEditorSite.getActionBarContributor();
if (!state && globalActionHandlerDeaction == null) {
globalActionHandlerDeaction = new DeactivateGlobalActionHandlers(multiEditorSite.getActionBars());
if (actionBarContributor == null) {
multiEditorSite.getMultiPageEditor().getEditorSite().getActionBarContributor()
.setActiveEditor(null);
}
} else if (state && globalActionHandlerDeaction != null) {
globalActionHandlerDeaction.reactivate();
globalActionHandlerDeaction = null;
if (actionBarContributor == null) {
MultiPageEditorPart multiPageEditor = multiEditorSite.getMultiPageEditor();
multiPageEditor.getEditorSite().getActionBarContributor()
.setActiveEditor(multiPageEditor);
}
}
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
import org.eclipse.jface.text.source.VerticalRuler;

import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
Expand Down Expand Up @@ -5212,10 +5213,15 @@ public void setAction(String actionID, IAction action) {
/**
* Sets this editor's actions into activated (default) or deactived state.
* <p>
* XXX: This is called by the Java editor for its breadcrumb feature. We
* don't want to make this risky method API because the Java editor
* breadcrumb might become a Platform UI feature during 3.5 and hence we can
* then delete this workaround.
* XXX: This is called by the Java editor for its breadcrumb feature. We don't
* want to make this risky method API because the Java editor breadcrumb might
* become a Platform UI feature during 3.5 and hence we can then delete this
* workaround.
* </p>
* <p>
* This is also called reflectively by
* org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlay.targetActionActivationHandling.new
* FocusListener() {...}.setTextEditorActionsActivated(boolean).
* </p>
*
* @param state <code>true</code> if activated
Expand All @@ -5230,9 +5236,17 @@ private void setActionActivation(boolean state) {
if (action != null)
fActivationCodeTrigger.registerActionForKeyActivation(action);
}
getEditorSite().getActionBarContributor().setActiveEditor(this);
// Handle that MultiPageEditorSite.getActionBarContributor() returns null.
IEditorActionBarContributor actionBarContributor = getEditorSite().getActionBarContributor();
if (actionBarContributor != null) {
actionBarContributor.setActiveEditor(this);
}
} else {
getEditorSite().getActionBarContributor().setActiveEditor(null);
// Handle that MultiPageEditorSite.getActionBarContributor() returns null.
IEditorActionBarContributor actionBarContributor = getEditorSite().getActionBarContributor();
if (actionBarContributor != null) {
actionBarContributor.setActiveEditor(null);
}
Iterator<IAction> iter= fActions.values().iterator();
while (iter.hasNext()) {
IAction action= iter.next();
Expand Down

0 comments on commit aa689b8

Please sign in to comment.