Skip to content

NullPointerException in DefaultHelpUi.displayContext #1689

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

Open
2wendex2 opened this issue Jan 16, 2025 · 3 comments · May be fixed by #1863
Open

NullPointerException in DefaultHelpUi.displayContext #1689

2wendex2 opened this issue Jan 16, 2025 · 3 comments · May be fixed by #1863
Labels
bug Something isn't working

Comments

@2wendex2
Copy link

2wendex2 commented Jan 16, 2025

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 2wendex2 added the bug Something isn't working label Jan 16, 2025
@jukzi
Copy link
Contributor

jukzi commented Jan 17, 2025

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 jukzi added the needinfo label Jan 17, 2025
@2wendex2
Copy link
Author

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

@jukzi jukzi removed the needinfo label Jan 17, 2025
@jukzi
Copy link
Contributor

jukzi commented Jan 17, 2025

good, can you provide a fix, please?

SougandhS added a commit to SougandhS/eclipse.platform that referenced this issue May 8, 2025
Check whether context is null or not before invoking getText()

Fixes : eclipse-platform#1689
@SougandhS SougandhS linked a pull request May 8, 2025 that will close this issue
SougandhS added a commit to SougandhS/eclipse.platform that referenced this issue May 13, 2025
Check whether context is null or not before invoking getText()

Fixes : eclipse-platform#1689
SougandhS added a commit to SougandhS/eclipse.platform that referenced this issue May 29, 2025
Check whether context is null or not before invoking getText()

Fixes : eclipse-platform#1689
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants