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

Bug 336487

Summary: [Help][Context] NPE in ContextHelpDialog when context has no description
Product: [Eclipse Project] Platform Reporter: Anton Leherbauer <aleherb+eclipse>
Component: User AssistanceAssignee: Chris Goldthorpe <cgold>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: cgold, mober.at+eclipse
Version: 3.6   
Target Milestone: 3.7 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch none

Description Anton Leherbauer CLA 2011-02-07 05:48:21 EST
Opening a context which does not contain a description element will cause an NPE in the ContextHelpDialog:

java.lang.NullPointerException
	at org.eclipse.help.ui.internal.ContextHelpDialog.createInfoArea(ContextHelpDialog.java:231)
	at org.eclipse.help.ui.internal.ContextHelpDialog.createContents(ContextHelpDialog.java:213)
	at org.eclipse.help.ui.internal.ContextHelpDialog.<init>(ContextHelpDialog.java:171)
	at org.eclipse.help.ui.internal.DefaultHelpUI.displayContextAsInfopop(DefaultHelpUI.java:413)
	at org.eclipse.help.ui.internal.DefaultHelpUI.displayContext(DefaultHelpUI.java:308)
	at org.eclipse.help.ui.internal.DefaultHelpUI.displayContext(DefaultHelpUI.java:289)
	at org.eclipse.ui.internal.help.WorkbenchHelpSystem.displayContext(WorkbenchHelpSystem.java:905)
	at org.eclipse.ui.internal.help.WorkbenchHelpSystem.displayHelp(WorkbenchHelpSystem.java:933)


Looking at the code in ContextHelpDialog line 228ff, it looks like the null checks are somewhat inconsequent.  The second if is quite useless, because at this point styledText is either non-null or a NPE was already thrown.  Note also the useless duplicate assignment.

if (styledText == null) {
	styledText = context.getText();
	styledText = context.getText();
	styledText= styledText.replaceAll("<b>","<@#\\$b>");
	styledText= styledText.replaceAll("</b>", "</@#\\$b>");
}
if (styledText == null) { // no description found in context objects.
	styledText = Messages.ContextHelpPart_noDescription;
}
Comment 1 Martin Oberhuber CLA 2011-02-07 10:10:49 EST
CQ:WIND00254022

Specification of the org.eclipse.help.contexts extension point and the respective contexts.xml file format clearly says that the <description> element is optional:

http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/ua_help_context_xml.htm

"Each context element can have an optional <description> element ..."

Running into an NPE therefore violates the spec.

Workaround: have an empty <description></description> element in contexts.xml
Comment 2 Chris Goldthorpe CLA 2011-02-07 12:22:47 EST
This is easy to fix in Eclipse 3.7 but too late for 3.6.2. The way the code is written the intention is to show this as the description if none is provided.

"No description was provided for this user interface element."

I am not sure that this has any value to the user who is trying to get some help, maybe it would be better to show an empty description rather than this message.
Comment 3 Martin Oberhuber CLA 2011-02-07 17:13:43 EST
My expectation is that when there's a SINGLE context contributed only, and no description exists, it directly navigates into the help rather than showing an infopop first.
Comment 4 Chris Goldthorpe CLA 2011-02-07 18:47:49 EST
If there is no description and exactly one topic the help system will indeed take you straight to the help topic. This bug only shows when there are two or more topics and no description.
Comment 5 Martin Oberhuber CLA 2011-02-08 00:47:10 EST
Then I would suggest doing something similar as when NLS is not available, ie print the internal context ID as pert of the "description missing" message when there's 2 or more contexts available.
Comment 6 Chris Goldthorpe CLA 2011-02-08 13:21:04 EST
Created attachment 188540 [details]
Patch

The situation is slightly different from NLS not available in that having no description is not considered and error. Here's a patch that eliminates the NPE.
Comment 7 Chris Goldthorpe CLA 2011-02-08 13:21:49 EST
Patch committed to HEAD, Fixed.