-
Notifications
You must be signed in to change notification settings - Fork 196
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
Avoid FindReplaceOverlay setTextEditorActionsActivated resulting in NPE #2724
Conversation
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.
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. |
- 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.
aa689b8
to
e90c9a6
Compare
This solution is simpler and I think more correct. |
There was a problem hiding this 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.
There was a problem hiding this 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.