Skip to content

Commit 1e3db4a

Browse files
committed
Avoid FindReplaceOverlay setTextEditorActionsActivated resulting in NPE
- 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 and instead should get and use the action bar contributor of the containing multi-page editor.
1 parent 3eaaeb6 commit 1e3db4a

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java

+27-6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
import org.eclipse.jface.text.source.VerticalRuler;
189189

190190
import org.eclipse.ui.IActionBars;
191+
import org.eclipse.ui.IEditorActionBarContributor;
191192
import org.eclipse.ui.IEditorDescriptor;
192193
import org.eclipse.ui.IEditorInput;
193194
import org.eclipse.ui.IEditorPart;
@@ -5212,10 +5213,15 @@ public void setAction(String actionID, IAction action) {
52125213
/**
52135214
* Sets this editor's actions into activated (default) or deactived state.
52145215
* <p>
5215-
* XXX: This is called by the Java editor for its breadcrumb feature. We
5216-
* don't want to make this risky method API because the Java editor
5217-
* breadcrumb might become a Platform UI feature during 3.5 and hence we can
5218-
* then delete this workaround.
5216+
* XXX: This is called by the Java editor for its breadcrumb feature. We don't
5217+
* want to make this risky method API because the Java editor breadcrumb might
5218+
* become a Platform UI feature during 3.5 and hence we can then delete this
5219+
* workaround.
5220+
* </p>
5221+
* <p>
5222+
* This is also called reflectively by
5223+
* org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlay.targetActionActivationHandling.new
5224+
* FocusListener() {...}.setTextEditorActionsActivated(boolean).
52195225
* </p>
52205226
*
52215227
* @param state <code>true</code> if activated
@@ -5230,9 +5236,9 @@ private void setActionActivation(boolean state) {
52305236
if (action != null)
52315237
fActivationCodeTrigger.registerActionForKeyActivation(action);
52325238
}
5233-
getEditorSite().getActionBarContributor().setActiveEditor(this);
5239+
setActiveEditor(this);
52345240
} else {
5235-
getEditorSite().getActionBarContributor().setActiveEditor(null);
5241+
setActiveEditor(null);
52365242
Iterator<IAction> iter= fActions.values().iterator();
52375243
while (iter.hasNext()) {
52385244
IAction action= iter.next();
@@ -5243,6 +5249,21 @@ private void setActionActivation(boolean state) {
52435249
}
52445250
}
52455251

5252+
private void setActiveEditor(IEditorPart targetEditor) {
5253+
IEditorSite editorSite = getEditorSite();
5254+
IEditorActionBarContributor actionBarContributor = editorSite.getActionBarContributor();
5255+
// Handle that MultiPageEditorSite.getActionBarContributor() returns null.
5256+
if (actionBarContributor == null) {
5257+
if (editorSite instanceof MultiPageEditorSite multiPageEditorSite) {
5258+
actionBarContributor = multiPageEditorSite.getMultiPageEditor().getEditorSite()
5259+
.getActionBarContributor();
5260+
}
5261+
}
5262+
if (actionBarContributor != null) {
5263+
actionBarContributor.setActiveEditor(targetEditor);
5264+
}
5265+
}
5266+
52465267
private static final boolean HACK_TO_SUPPRESS_UNUSUED_WARNING= false;
52475268
{
52485269
if (HACK_TO_SUPPRESS_UNUSUED_WARNING)

0 commit comments

Comments
 (0)