Bug 196335 - [Schema][Editors] Element with no name causes NPEs
Summary: [Schema][Editors] Element with no name causes NPEs
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M1   Edit
Assignee: Adam Archer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-07-12 11:25 EDT by Mike Pawlowski CLA
Modified: 2007-07-16 17:15 EDT (History)
1 user (show)

See Also:
mike.pawlowski: review+


Attachments
patch (4.35 KB, patch)
2007-07-13 19:02 EDT, Adam Archer CLA
mike.pawlowski: review+
Details | Diff
patch correcting the problem (3.60 KB, patch)
2007-07-16 15:45 EDT, Adam Archer CLA
mike.pawlowski: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Pawlowski CLA 2007-07-12 11:25:07 EDT
Steps To Reproduce:

(1) Create a new extension point schema
(2) Create a new element
(3) Delete the new element's name by making the "Name" field empty
(4) Switch to the source page
(5) Switch back to the "Definition" form page
    -> BUG:  NPE produced (see below)

At this point everything goes haywire because the model is corrupt.

There are two problems here:
(1) The form page allows the user to specify an empty element name
    -> If the user specifies an empty field name, we should revert
       it back to a previous valid value (perhaps when the focus is lost?)
(2) The schema model does not guard against empty names on load
    -> We should guard against NPEs

java.lang.NullPointerException
	at org.eclipse.pde.internal.core.schema.Schema.processElement(Schema.java:646)
	at org.eclipse.pde.internal.core.schema.Schema.traverseDocumentTree(Schema.java:923)
	at org.eclipse.pde.internal.core.schema.Schema.load(Schema.java:391)
	at org.eclipse.pde.internal.core.schema.Schema.reload(Schema.java:783)
	at org.eclipse.pde.internal.ui.editor.schema.SchemaInputContext.synchronizeModel(SchemaInputContext.java:160)
	at org.eclipse.pde.internal.ui.editor.context.InputContext.synchronizeModelIfNeeded(InputContext.java:360)
	at org.eclipse.pde.internal.ui.editor.context.InputContext.isModelCorrect(InputContext.java:382)
	at org.eclipse.pde.internal.ui.editor.XMLSourcePage.canLeaveThePage(XMLSourcePage.java:27)
	at org.eclipse.ui.forms.editor.FormEditor.pageChange(FormEditor.java:478)
	at org.eclipse.pde.internal.ui.editor.PDEFormEditor.pageChange(PDEFormEditor.java:290)
Comment 1 Adam Archer CLA 2007-07-13 19:02:00 EDT
Created attachment 73782 [details]
patch

With this patch, when the attribute name and element name fields lose focus, their text will be reverted to the previous contents if they are empty. This will leave the editor in a dirty state even if it was not previously similarly to pressing the escape key. I have opened bug 196520 to address the issue of the escape key leaving the editor dirty. When there is a fix available for that, it should be applied to this case as well.

This patch also marks the schema model as invalid if any element or attribute names are empty when it is built. This results in the user being unable to leave the source page if they enter an empty name.
Comment 2 Adam Archer CLA 2007-07-16 10:21:00 EDT
Based on bug 196520 comment 1, it is fine that this patch leaves the editor in a dirty state after reverting the name.
Comment 3 Mike Pawlowski CLA 2007-07-16 11:15:29 EDT
Comment on attachment 73782 [details]
patch

Excellent patch, Adam.  Thanks.
Comment 4 Mike Pawlowski CLA 2007-07-16 11:16:02 EDT
Patch applied to HEAD.

Target: 3.4 M1
Comment 5 Mike Pawlowski CLA 2007-07-16 15:18:06 EDT
Unfortunately, the patch causes compositors not to be loaded correctly.  
Upon closer inspection one method is being used to process both elements and element references so null is a valid value for the "name" attribute if an element reference is being processed.

Sorry Adam, I should have caught this.
Comment 6 Adam Archer CLA 2007-07-16 15:45:21 EDT
Created attachment 73889 [details]
patch correcting the problem

This patch is to be applied on top of the previous one. It corrects the compositor loading problem.

The processElement method is split into processElementReference and processElementDeclaration to avoid confusion in the future.
Comment 7 Mike Pawlowski CLA 2007-07-16 17:15:08 EDT
Comment on attachment 73889 [details]
patch correcting the problem

Tested well, Adam.  Thanks.
Comment 8 Mike Pawlowski CLA 2007-07-16 17:15:41 EDT
Patch released to HEAD.