Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 196544 - XML editor "format" gets null pointer exception on DocBook 4.5 "screen" elements
Summary: XML editor "format" gets null pointer exception on DocBook 4.5 "screen" elements
Status: VERIFIED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.0.2 M202   Edit
Assignee: Nick Sandonato CLA
QA Contact: David Williams CLA
URL:
Whiteboard: PMC_approved
Keywords:
: 159566 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-07-14 11:30 EDT by Johnson Earls CLA
Modified: 2008-02-23 14:18 EST (History)
7 users (show)

See Also:
david_williams: pmc_approved+
thatnitind: pmc_approved? (raghunathan.srinivasan)
thatnitind: pmc_approved? (naci.dai)
deboer: pmc_approved+
thatnitind: pmc_approved? (neil.hauge)
for.work.things: review+
thatnitind: review+


Attachments
proposed patch (1.62 KB, patch)
2008-01-30 13:12 EST, Nick Sandonato CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Johnson Earls CLA 2007-07-14 11:30:21 EDT
Build ID: I20070625-1500 (as reported by Help/About Eclipse) I20070608-1718 (as reported by the error log)

Steps To Reproduce:
Obtain DocBook 4.5 xml DTD from http://www.oasis-open.org/docbook/xml/4.5/docbook-xml-4.5.zip

Create a new XML file using that DTD.  Make the XML file look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" ".../docbookx.dtd" >
<book><title>Testing</title><chapter><title>Test</title>
<para><screen>screen test</screen></para>
</chapter></book>

Select all and use CTRL-SHIFT-F to format.

More information:

From the "Problem Occurred" Dialog box:

"Format" did not complete normally.  Please see the log for more information.
(Time of error: ...)
Reason:
java.lang.NullPointerException


Exception Stack Trace from log:

java.lang.NullPointerException
at org.eclipse.wst.xml.core.internal.provisional.format.ElementNodeFormatter.formatStartTag(ElementNodeFormatter.java:395)
at org.eclipse.wst.xml.core.internal.provisional.format.ElementNodeFormatter.formatNode(ElementNodeFormatter.java:121)
at org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter.format(NodeFormatter.java:75)
at org.eclipse.wst.xml.core.internal.provisional.format.DocumentNodeFormatter.formatChildren(DocumentNodeFormatter.java:42)
at org.eclipse.wst.xml.core.internal.provisional.format.ElementNodeFormatter.formatNode(ElementNodeFormatter.java:132)
at org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter.format(NodeFormatter.java:75)
at org.eclipse.wst.xml.core.internal.provisional.format.DocumentNodeFormatter.formatChildren(DocumentNodeFormatter.java:42)
at org.eclipse.wst.xml.core.internal.provisional.format.ElementNodeFormatter.formatNode(ElementNodeFormatter.java:132)
at org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter.format(NodeFormatter.java:75)
at org.eclipse.wst.xml.core.internal.provisional.format.DocumentNodeFormatter.formatChildren(DocumentNodeFormatter.java:42)
at org.eclipse.wst.xml.core.internal.provisional.format.ElementNodeFormatter.formatNode(ElementNodeFormatter.java:132)
at org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter.format(NodeFormatter.java:75)
at org.eclipse.wst.sse.core.internal.format.AbstractStructuredFormatProcessor.formatNode(AbstractStructuredFormatProcessor.java:405)
at org.eclipse.wst.sse.core.internal.format.AbstractStructuredFormatProcessor.formatModel(AbstractStructuredFormatProcessor.java:346)
at org.eclipse.wst.sse.core.internal.format.AbstractStructuredFormatProcessor.formatDocument(AbstractStructuredFormatProcessor.java:167)
at org.eclipse.wst.sse.ui.internal.format.StructuredFormattingStrategy.format(StructuredFormattingStrategy.java:58)
at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatMaster(MultiPassContentFormatter.java:193)
at org.eclipse.jface.text.formatter.MultiPassContentFormatter.format(MultiPassContentFormatter.java:135)
at org.eclipse.wst.sse.ui.internal.StructuredTextViewer.doOperation(StructuredTextViewer.java:454)
at org.eclipse.ui.texteditor.TextOperationAction$1.run(TextOperationAction.java:131)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at org.eclipse.ui.texteditor.TextOperationAction.run(TextOperationAction.java:129)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:475)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:429)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:165)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:470)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:821)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:879)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:568)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:510)
at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:126)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1141)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:937)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:975)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:971)
at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1285)
at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3772)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:3672)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:291)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4351)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2264)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3291)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
Comment 1 Johnson Earls CLA 2007-07-14 13:35:21 EDT
Better information:  This apparently happens on any element with xml:space set to preserve.  DTD and XML file follow.  The DTD defines a "workingElement" and "nonWorkingElement".  Both can include either element, plus #PCDATA.  The nonWorkingElement has an implied 'xml:space' attribute set to 'preserve'.

When the XML file is entered and formatted, the <workingElement> section is reformatted, then a null pointer exception happens at the <nonWorkingElement>.

<!-- test DTD to create minimal repro for xml:space problem -->

<!ELEMENT testcase (workingElement|nonWorkingElement)*>

<!ELEMENT workingElement (#PCDATA|workingElement|nonWorkingElement)*>

<!ELEMENT nonWorkingElement (#PCDATA|workingElement|nonWorkingElement)*>
<!ATTLIST nonWorkingElement
    xml:space  (preserve)      #IMPLIED
>

<!-- end of DTD -->



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE testcase SYSTEM "test.dtd" >
<testcase>
<workingElement> This section <workingElement> will be properly </workingElement> reformatted. </workingElement>
<nonWorkingElement> This section <workingElement> will not be </workingElement> reformatted. </nonWorkingElement>
</testcase>
Comment 2 Johnson Earls CLA 2007-07-23 20:39:09 EDT
As far as I can tell, this is caused by the definition of getImpliedValue() in org.eclipse.wst.xml.core.internal.contentmodel.basic.CMDataTypeImpl always returning null.
Comment 3 Nitin Dahyabhai CLA 2007-07-24 04:53:25 EDT
If the implied value kind is IMPLIED_VALUE_NONE, it would return null.  We should actually only make use of the implied value for IMPLIED_VALUE_FIXED and IMPLIED_VALUE_DEFAULT, and then still check for nulls.
Comment 4 Amy Wu CLA 2008-01-29 15:27:06 EST
Reassigning formatting bugs to Nick
Comment 5 Nick Sandonato CLA 2008-01-30 13:12:57 EST
Created attachment 88317 [details]
proposed patch

See Bug 159566.  This seems to be something that has existed since 1.5.
Comment 6 Nick Sandonato CLA 2008-01-30 13:30:36 EST
*** Bug 159566 has been marked as a duplicate of this bug. ***
Comment 7 Amy Wu CLA 2008-02-05 11:28:25 EST
Targetting 2.0.2 since this is only a problem prior to the new formatter in wtp 3.0.
Comment 8 Nick Sandonato CLA 2008-02-07 15:33:57 EST
    * Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 
      - It's been reported more than once in bug reports and it's also been reported on the newsgroup.

    * Is there a work-around? If so, why do you believe the work-around is insufficient? 
      - No

    * How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added?
      - This fix has been tested against the content defined in the bug's original description.  

    * Give a brief technical overview. Who has reviewed this fix?
      - The problem occurs when there is no implied value for an attribute. The null value had the .compareTo method called on it, and caused the NPE. To fix this, .equals was used on a String value that would not be null.

    * What is the risk associated with this fix?
      - This fix should have very little associated risk.
Comment 9 Amy Wu CLA 2008-02-07 19:19:47 EST
Fix looks good, low risk.
Comment 10 Nitin Dahyabhai CLA 2008-02-12 19:52:23 EST
Patch approved, marking for PMC review.
Comment 11 Tim deBoer CLA 2008-02-13 08:45:53 EST
Approved.
Comment 12 Nitin Dahyabhai CLA 2008-02-14 01:27:35 EST
Released.
Comment 13 Nitin Dahyabhai CLA 2008-02-23 14:18:03 EST
Verified with M-2.0.2RC3-20080221101112