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

getTMPresentationReconciler textViewer usage causes errors logged for other ITextViewer implementations #281

Closed
GeraldMit opened this issue Sep 13, 2021 · 1 comment

Comments

@GeraldMit
Copy link
Contributor

IPresentationReconciler presentationReconciler = (IPresentationReconciler) field.get(textViewer);

After file opens in a custom Editor, attempting to open a context menu results in

Error
---date---
Can not set org.eclipse.jface.text.presentation.IPresentationReconciler field org.eclipse.jface.text.source.SourceViewer.fPresentationReconciler to ---non-related SourceViewer---

java.lang.IllegalArgumentException: Can not set org.eclipse.jface.text.presentation.IPresentationReconciler field org.eclipse.jface.text.source.SourceViewer.fPresentationReconciler to ---non-related SourceViewer---
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:179)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:183)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:70)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:48)
at java.lang.reflect.Field.get(Field.java:403)
at org.eclipse.tm4e.ui.text.TMPresentationReconciler.getTMPresentationReconciler(TMPresentationReconciler.java:782)
at org.eclipse.tm4e.ui.text.TMPresentationReconciler.getTMPresentationReconciler(TMPresentationReconciler.java:764)
at org.eclipse.tm4e.ui.internal.menus.ThemeContribution.getContributionItems(ThemeContribution.java:58)
at org.eclipse.ui.actions.CompoundContributionItem.getContributionItemsToFill(CompoundContributionItem.java:80)
at org.eclipse.ui.actions.CompoundContributionItem.fill(CompoundContributionItem.java:54)
at org.eclipse.ui.internal.menus.DynamicMenuContributionItem.fill(DynamicMenuContributionItem.java:147)
at org.eclipse.jface.action.MenuManager.doItemFill(MenuManager.java:728)
at org.eclipse.jface.action.MenuManager.update(MenuManager.java:810)
at org.eclipse.jface.action.MenuManager.update(MenuManager.java:669)
at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.scheduleManagerUpdate(MenuManagerRenderer.java:1219)
at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.subscribeUIElementTopicAllRenderedVisibility(MenuManagerRenderer.java:200)
at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler$1.run(UIEventObjectSupplier.java:64)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4567)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler.handleEvent(UIEventObjectSupplier.java:61)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:196)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.UIElementImpl.setVisible(UIElementImpl.java:346)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributionRecord.updateVisibility(ContributionRecord.java:110)
at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRendererFilter.updateElementVisibility(MenuManagerRendererFilter.java:191)
at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRendererFilter.updateElementVisibility(MenuManagerRendererFilter.java:202)
at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerShowProcessor.showMenu(MenuManagerShowProcessor.java:255)
at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerShowProcessor.menuAboutToHide(MenuManagerShowProcessor.java:112)
at org.eclipse.jface.internal.MenuManagerEventHelper.showEventPostHelper(MenuManagerEventHelper.java:92)
at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:471)
at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:465)
at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:497)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:256)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4118)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1076)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
at org.eclipse.swt.widgets.Control.WM_INITMENUPOPUP(Control.java:5116)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4785)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:345)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1499)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2152)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4757)
at org.eclipse.swt.internal.win32.OS.TrackPopupMenu(Native Method)
at org.eclipse.swt.widgets.Menu._setVisible(Menu.java:250)
at org.eclipse.swt.widgets.Display.runPopups(Display.java:3972)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3528)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1170)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1059)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:667)
at org.eclipse.ui.internal.Workbench$$Lambda$48/0x0000000065e7cc00.run(Unknown Source)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:597)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)
at org.eclipse.equinox.launcher.Main.run(Main.java:1498)
at org.eclipse.equinox.launcher.Main.main(Main.java:1471)

For any use of TM4E after 0.3.3, this exception is no longer absorbed and floods the logs after
TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e));
was added.

The code has an assumption that the textViewer implementation is from SourceViewer from an ITextViewer parameter
org.eclipse.jface.text.source.ISourceViewer extends org.eclipse.jface.text.source.ITextViewer
Implementing Classes:org.eclipse.jface.text.source.SourceViewer

Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler");
This doesn't check that that field actually exists on textViewer before trying to get textViewer's field value, nor that textViewer is an instance of SourceViewer ( ISourceViewer can be implemented elsewhere)
I think there should be a check that textViewer is an instance of SourceViewer but also that field isn't null.

IPresentationReconciler presentationReconciler = (IPresentationReconciler) field.get(textViewer);
return presentationReconciler instanceof TMPresentationReconciler ? (TMPresentationReconciler) presentationReconciler : null;

instead I think that the code should have
IPresentationReconciler presentationReconciler = field == null ? null : (IPresentationReconciler) field.get(textViewer);

@mickaelistria
Copy link
Contributor

Please submit a PR for that.

GeraldMit added a commit to GeraldMit/tm4e that referenced this issue Sep 26, 2021
Remove error for textViewer not an instance of SourceViewer

Change-Id: I6c5dbacd489b5094f0ae958f0bb40e27bb79c8b6
Signed-off-by: GeraldMit <Gerald.Mitchell@ibm.com>
GeraldMit added a commit to GeraldMit/tm4e that referenced this issue Sep 26, 2021
Remove error for textViewer not an instance of SourceViewer; Update TM4E
to 4.3

Change-Id: I6c5dbacd489b5094f0ae958f0bb40e27bb79c8b6
Signed-off-by: GeraldMit <Gerald.Mitchell@ibm.com>
GeraldMit added a commit to GeraldMit/tm4e that referenced this issue Sep 27, 2021
Remove error for textViewer not an instance of SourceViewer

Change-Id: I6c5dbacd489b5094f0ae958f0bb40e27bb79c8b6
Signed-off-by: GeraldMit <Gerald.Mitchell@ibm.com>
GeraldMit added a commit to GeraldMit/tm4e that referenced this issue Sep 27, 2021
Remove error for textViewer not an instance of SourceViewer; Update TM4E
UI to 4.3 and feature to 4.4

Change-Id: I6c5dbacd489b5094f0ae958f0bb40e27bb79c8b6
Signed-off-by: GeraldMit <Gerald.Mitchell@ibm.com>
mickaelistria pushed a commit that referenced this issue Sep 27, 2021
Remove error for textViewer not an instance of SourceViewer
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

No branches or pull requests

2 participants