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

Bug 332203

Summary: NPE on EMF2SSEDOMAdapter
Product: [WebTools] WTP Common Tools Reporter: saurav sarkar <saurav.sarkar1>
Component: wst.commonAssignee: Carl Anderson <ccc>
Status: RESOLVED FIXED QA Contact: Carl Anderson <ccc>
Severity: normal    
Priority: P3 CC: jsholl, thatnitind
Version: 3.1Flags: ccc: review+
Target Milestone: 3.2.3   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Check to see if the emfObject is null none

Description saurav sarkar CLA 2010-12-09 06:15:35 EST
Hi All,

We have been using EMF2DOMSSE Adapter in our EMF Models.

On unsetting of a feature ,notification is triggered and  the target of the adapter is set to null.
Then due to this null we get an NPE at the Translator code.

Please find the stacktrace below.

Message : A structured model client, EMF2DOMSSEAdapter(library,LibraryImpl) threw following exception during adapter notification (STRUCTURE_CHANGED )

<code>
java.lang.NullPointerException
	at org.eclipse.wst.common.internal.emf.resource.Translator.featureExists(Translator.java:475)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.primUpdateMOFFeature(EMF2DOMAdapterImpl.java:1359)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.updateMOFFeature(EMF2DOMAdapterImpl.java:1775)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.primUpdateMOF(EMF2DOMAdapterImpl.java:935)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.updateMOF(EMF2DOMAdapterImpl.java:915)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.primUpdateMOFFeature(EMF2DOMAdapterImpl.java:1443)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.updateMOFFeature(EMF2DOMAdapterImpl.java:1775)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.primUpdateMOF(EMF2DOMAdapterImpl.java:935)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.updateMOF(EMF2DOMAdapterImpl.java:915)
	at org.eclipse.wst.xml.core.internal.emf2xml.EMF2DOMSSEAdapter.notifyChanged(EMF2DOMSSEAdapter.java:230)
	at org.eclipse.wst.sse.core.internal.provisional.AbstractNotifier.notify(AbstractNotifier.java:201)
	at org.eclipse.wst.xml.core.internal.document.XMLModelNotifierImpl.notifyStructureChanged(XMLModelNotifierImpl.java:392)
	at org.eclipse.wst.xml.core.internal.document.XMLModelNotifierImpl.structureChanged(XMLModelNotifierImpl.java:454)
	at org.eclipse.wst.xml.core.internal.document.XMLModelNotifierImpl.childReplaced(XMLModelNotifierImpl.java:160)
	at org.eclipse.wst.xml.core.internal.document.DOMModelImpl.childReplaced(DOMModelImpl.java:191)
	at org.eclipse.wst.xml.core.internal.document.NodeContainer.notifyChildReplaced(NodeContainer.java:357)
	at org.eclipse.wst.xml.core.internal.document.NodeContainer.removeChild(NodeContainer.java:401)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.removeDOMChild(EMF2DOMAdapterImpl.java:690)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.removeDOMChild(EMF2DOMAdapterImpl.java:676)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.updateDOMSubtree(EMF2DOMAdapterImpl.java:1661)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.primUpdateDOMFeature(EMF2DOMAdapterImpl.java:1325)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.updateDOMFeature(EMF2DOMAdapterImpl.java:1553)
	at org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl.notifyChanged(EMF2DOMAdapterImpl.java:1040)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:280)
</code>

The code from where it is thrown

<code>
/**
	 * Check to see if feature is valid on a particular mofObject.
	 * 
	 * @return boolean Return true if the feature specified exists on the MOF object.
	 * @param emfObject
	 *            org.eclipse.emf.ecore.EObject
	 */
	public boolean featureExists(EObject emfObject) {
		if (feature == null)
			return false;

		return emfObject.eClass().getEStructuralFeature(feature.getName()) != null;
	}
</code>


Please close it if the bug already exsist or let me know if i need to provide further details.

cheers,
Saurav
Comment 1 Carl Anderson CLA 2010-12-09 17:33:28 EST
The WTP 3.1.x stream is now closed- the latest available stream would be WTP 3.2.3.

The return statement is the line causing the NPE.

There's already a check to make sure that feature is not null.  Therefore my assumption is that emfObject is null.
Comment 2 Carl Anderson CLA 2010-12-09 17:35:38 EST
Created attachment 184910 [details]
Check to see if the emfObject is null
Comment 3 saurav sarkar CLA 2010-12-09 21:41:01 EST
(In reply to comment #1)
> The WTP 3.1.x stream is now closed- the latest available stream would be WTP
> 3.2.3.
> 
> The return statement is the line causing the NPE.
> 
> There's already a check to make sure that feature is not null.  Therefore my
> assumption is that emfObject is null.

Yes pretty much the emfObject is null here.
Comment 4 Carl Anderson CLA 2010-12-09 22:43:16 EST
Committed to R3_2_maintenance for R3.2.3.

I will commit this to HEAD for WTP 3.3 as soon as M4 is declared.
Comment 5 Jason Sholl CLA 2010-12-15 14:29:16 EST
Code checked into HEAD for 3.3; this was previously checked into 32M for 3.2.3