Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351176

Summary: [Doc] NullPointerException when implementing IContext.getRelatedTopics to return null
Product: [Eclipse Project] Platform Reporter: Henno Vermeulen <strider80>
Component: User AssistanceAssignee: Chris Goldthorpe <cgold>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: cgold
Version: 4.0   
Target Milestone: 3.8 M3   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Henno Vermeulen CLA 2011-07-05 08:38:10 EDT
Build Identifier: 20110615-0604

I am programmatically implementing my own context help by creating an AbstractContextProvider that returns my own IContext implementation.
The Javadoc for IContext.getRelatedTopics states that it is allowed to return null when there are no related topics. However when I return null, I get a NullPointerException when opening the context sensitive help in a preference page:

java.lang.NullPointerException
	at org.eclipse.help.internal.context.Context.mergeContext(Context.java:66)
....

This is because there is a for loop over the value returned by getRelatedTopics.
Either this implementation needs to check for nulls or the javadoc should be adjusted to state that nulls are illegal.

Workaround: simply return new IHelpResource[0]

Reproducible: Always

Steps to Reproduce:
1. Create your own context provider and register it with extension point org.eclipse.help.contexts
2. Let it return an IContext implementation that returns null on getRelatedTopics()
3. Create a preference page that sets this context on Composite parent in the createControl method.
4. Open the preference page and press the help key (F1 on windows)
Comment 1 Henno Vermeulen CLA 2011-07-05 08:57:17 EDT
Not sure if it is easily reproducible by these steps because it probably only occurs when ContextFileProvider.getContext decides to merge contexts. I have overwritten org.eclipse.ui.preference_dialog_context. However if the Javadoc is changed the bug is quickly fixed and doesn't need to get reproduced.
Comment 2 Chris Goldthorpe CLA 2011-07-06 18:39:31 EDT
You are correct, it is a bug. Targeting Eclipse 3.8 - since there is an easy workaround there is no need to fix in 3.7.1.
Comment 3 Chris Goldthorpe CLA 2011-10-19 14:17:25 EDT
It appears that there are at least three locations where the result of this function is used without testing from null. I will edit the javadoc to state that the result cannot be null.
Comment 4 Chris Goldthorpe CLA 2011-10-19 14:20:17 EDT
The documentation change has been committed with message:

Bug 351176 - [Doc] NullPointerException when implementing
IContext.getRelatedTopics to return null