Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid FindReplaceOverlay setTextEditorActionsActivated resulting in NPE #2724

Merged

Conversation

merks
Copy link
Contributor

@merks merks commented Jan 17, 2025

  • 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.

@merks
Copy link
Contributor Author

merks commented Jan 17, 2025

To reproduce the original problem open a *.target file with the PDE's Target Editor, turn to the Source tab and type Ctrl-F. I didn't even notice the logged errors initially, but I did notice that Ctrl-C didn't paste into the overlay but rather into the editor (and then I noticed that Revert didn't work for that editor, which is now fixed).

Anyway, I don't know if this is the right approach for fixing this. Also, given the careful order of actions in AbstractTextEditor.setActionActivation(boolean), the current change does not preserve that order/inverse-order for the setActiveEditor call and the processing of the actions. I think more refactoring would be needed if that order is important.

Please feel free to reuse this PR in any way, shape, or form, or to rewrite it.

Copy link
Contributor

github-actions bot commented Jan 17, 2025

Test Results

 1 818 files  ±0   1 818 suites  ±0   1h 27m 51s ⏱️ - 3m 57s
 7 739 tests ±0   7 511 ✅ ±0  228 💤 ±0  0 ❌ ±0 
24 378 runs  ±0  23 629 ✅ ±0  749 💤 ±0  0 ❌ ±0 

Results for commit e90c9a6. ± Comparison against base commit cc5231d.

♻️ This comment has been updated with latest results.

- 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.
@merks merks force-pushed the pr-multi-page-find-replace-overlay branch from aa689b8 to e90c9a6 Compare January 18, 2025 15:15
@merks
Copy link
Contributor Author

merks commented Jan 18, 2025

This solution is simpler and I think more correct.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @merks!

I have tested your change and it works for me as expected. Given that we accept the hack of reflectively calling setActionActivation(boolean), I agree that this is probably the right thing to do. I do not see a risk of regression, as the only other "user" (in terms of reflective access) of the changed method in addition to the FindReplaceOverlay is JDT's breadcrumb for Java editors. Since they are usually not placed inside MultiPageEditors, they will not be affected at all. And for the FindReplaceOverlay we already have some special handling for other kinds of MultiPageEditors.

Interestingly, PDE's MultiPageEditor for bundle information (MANIFEST, build.properties etc.) and this one for target files seem to behave differently, as they require different mechanism to temporarily deactivate the editor's actions.

This kind of hacking into the action activation is rather unsatisfying, as it is difficult to make and keep it work properly (see also #2651 for a related issue). From my understanding, this is all rooted in the fact that such addition/overlay implementations need their own action scope but as they do not participate in the ordinary workbench/part model handling the action activation, it required custom mechanisms.

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merks I'm not really familiar with this code, Heiko supervised this feature and knows the code.

@merks
Copy link
Contributor Author

merks commented Jan 21, 2025

The failing test:

image

and the new warnings:

image

are not related to this change.

@merks merks merged commit 1e3db4a into eclipse-platform:master Jan 21, 2025
13 of 17 checks passed
@merks merks deleted the pr-multi-page-find-replace-overlay branch January 21, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants