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

Bug 311777

Summary: NPE when editing an xml file which hoses the xml model
Product: [WebTools] WTP Source Editing Reporter: Karen Butzke <karenfbutzke>
Component: wst.xmlAssignee: Carl Anderson <ccc>
Status: VERIFIED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: major    
Priority: P1 CC: ccc, david_williams, neil.hauge, nsand.dev
Version: 3.2Flags: david_williams: pmc_approved+
thatnitind: pmc_approved? (raghunathan.srinivasan)
thatnitind: pmc_approved? (naci.dai)
thatnitind: pmc_approved? (deboer)
neil.hauge: pmc_approved+
thatnitind: pmc_approved? (kaloyan)
ccc: review+
thatnitind: review+
Target Milestone: 3.2 RC3   
Hardware: PC   
OS: Windows XP   
Whiteboard: PMC_approved
Bug Depends on:    
Bug Blocks: 314752    
Attachments:
Description Flags
NPE stack trace
none
example jpa project
none
proposed patch against head none

Description Karen Butzke CLA 2010-05-05 14:34:23 EDT
Created attachment 167193 [details]
NPE stack trace

The attached NPE occurs when I take a valid orm.xml file and edit it as follows.  Notice the '.' after class="model.Person".  Once the NPE has occurred the model is pretty well hosed.  You can tell this because of the Dali validation error: "The entity has no primary key attribute defined", which is not true since the 'id' element is specified. Removing the extraneous period does not solve the problem.  I will attach a JPA project that shows this bug, import the project, switch to the JPA perspective and open the orm.xml file.  Add the '.' and you will get the NPE.


<entity class="model.Person".>
        <table name="person"/>
        <attributes>
        	<id name="id">
        	</id>
        </attributes>
    </entity>
Comment 1 Karen Butzke CLA 2010-05-05 14:34:50 EDT
Created attachment 167194 [details]
example jpa project
Comment 2 Karen Butzke CLA 2010-05-05 14:36:59 EDT
Created attachment 167195 [details]
proposed patch against head

The attached patch fixes a bug in EMF2DOMSSEAdapter.createAdapter(Node, translator) that allowed a null adapter to be returned.  Line 287 of that method set the adapter to null and then primCreateAdapter(node, childMap) is never called.
Comment 3 Neil Hauge CLA 2010-05-11 14:09:42 EDT
Hi Nitin...I think you might be on vacation so copying David here.  Any chance this bug/patch can be resolved for RC1?
Comment 4 David Williams CLA 2010-05-11 14:26:01 EDT
CCing Nick and Carl (since in DOM adapter). Can't imagine a null check would be an undesired change in behavior.
Comment 5 David Williams CLA 2010-05-11 14:28:42 EDT
Marking as "P1" just to mean "needs a response" ... naturally, the fix is up to the active committers ... perhaps there's a better one? But, otherwise, please review. 

Thank you.
Comment 6 Nitin Dahyabhai CLA 2010-05-17 13:54:12 EDT
Carl, any thoughts?
Comment 7 Carl Anderson CLA 2010-05-18 10:24:44 EDT
I approve of this change, but I admit that it does pose a risk of a behavior change very late in the WTP 3.2 release cycle, and thus there is not enough time left to test this through usage, which is my only concern.  Here is the research and testing that I did to come to this conclusion:

The first thing I noticed when I reviewed this change was that there is a createAdapter() in the super class, EMF2DOMAdapter, which is identical to the createAdapter() in EMF2DOMSSEAdapter.

I tracked down the reason for the createAdapter() in EMF2DOMSSEAdapter- it was created in bug 232344.  Through extensive research, I found a few adopter scenarios that were fixed, in part, by 232344.  However, all of those scenarios have also been effected by other bugs- 232344 was not a complete fix for them.  I put a breakpoint on the adapter = null line, and even though I ran the exact scenarios, none of them encountered that line.

Last, one would expect a method named createAdapter() to actually create an adapter, if necessary.  The current implementation will, in Karen's scenario, find an existing adapter, remove it, and then return null.  Logically it makes sense in createAdapter to create a proper adapter for the node if the existing adapter is not the proper type.
Comment 8 Karen Butzke CLA 2010-05-18 11:06:16 EDT
Carl,
I don't understand how an identical protected method in a subclass could possibly be fixing a bug, how could that be necessary? That almost looks like it was a mistake made in the patch for bug 232344. Looks like the real fix is removing this method in EMF2DOMSSEEAdapter and fixing it in the superclass instead.
Comment 9 Nitin Dahyabhai CLA 2010-05-27 14:13:06 EDT
Approving Karen's patch as the safer short-term fix.
Comment 10 Nitin Dahyabhai CLA 2010-05-27 14:19:30 EDT
Released with +1/-0 during status call.
Comment 11 David Williams CLA 2010-05-29 16:07:35 EDT
please confirm, was this released to RC3? If so, please mark as "fixed". If not, should we rebuild RC3 for it?
Comment 12 Carl Anderson CLA 2010-05-29 23:38:34 EDT
I have verified that this was released for RC3 with the tag v201005271618
Comment 13 Karen Butzke CLA 2010-06-01 12:09:30 EDT
verified fixed in build S-3.2.0RC3-20100529234347