eclipse.platform icon indicating copy to clipboard operation
eclipse.platform copied to clipboard

NullPointerException in DefaultHelpUi.displayContext

Open 2wendex2 opened this issue 11 months ago • 3 comments

In ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/DefaultHelpUI.java, lines 330-336:

if (adapter != null)
	context = adapter.getContext(c);
String contextText = context.getText();

But javadoc of IContextProvider.getContext(Object) says:

return context help for the provided target or null if none is defined.

I.e. adapter.getContext(c) may return null then we call context.getText() and give NullPointerException.

2wendex2 avatar Jan 16 '25 15:01 2wendex2

If you have an actual NPE please quote the whole stacktrace and give a reproducer. Or are you just speculating that there is a possible NPE?

jukzi avatar Jan 17 '25 08:01 jukzi

@jukzi I have an actual NPE. Stack trace:

!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException: Cannot invoke "org.eclipse.help.IContext.getText()" because "context" is null
	at org.eclipse.help.ui.internal.DefaultHelpUI.displayContext(DefaultHelpUI.java:336)
	at org.eclipse.help.ui.internal.DefaultHelpUI.displayContext(DefaultHelpUI.java:305)
	at org.eclipse.ui.internal.help.WorkbenchHelpSystem.displayContext(WorkbenchHelpSystem.java:750)
	at org.eclipse.ui.internal.help.WorkbenchHelpSystem$WorkbenchHelpListener.helpRequested(WorkbenchHelpSystem.java:133)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:157)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4273)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4071)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3659)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:342)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:648)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:342)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:555)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:651)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:588)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1459)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1432)

To reproduce this you should a create your custom IContextProvider, in get context write return null and press F1.

2wendex2 avatar Jan 17 '25 12:01 2wendex2

good, can you provide a fix, please?

jukzi avatar Jan 17 '25 12:01 jukzi