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

Bug 341535

Summary: NullPointerException at org.eclipse.wst.xml.core.internal.document.DocumentImpl.getCMAttributes
Product: [WebTools] WTP Source Editing Reporter: Yahor Radtsevich <yahorr>
Component: wst.xmlAssignee: Nick Sandonato <nsand.dev>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: normal    
Priority: P3 CC: nsand.dev, yahorr
Version: unspecified   
Target Milestone: 3.3 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
JUnit for the bug
none
JUnit for the bug (as plain text)
none
Stack trace
none
Simple patch nsand.dev: iplog+

Description Yahor Radtsevich CLA 2011-03-31 15:15:51 EDT
Build Identifier: 3.3.0M6

There are no checking for null at the following line of the method DocumentImpl.getCMAttributes(...):
  CMElementDeclaration decl = ModelQueryUtil.getModelQuery(this).getCMElementDeclaration(element);


Reproducible: Always

Steps to Reproduce:
1. Run attached JUnit
Comment 1 Yahor Radtsevich CLA 2011-03-31 15:17:19 EDT
Created attachment 192314 [details]
JUnit for the bug
Comment 2 Yahor Radtsevich CLA 2011-03-31 15:18:13 EDT
Created attachment 192315 [details]
JUnit for the bug (as plain text)
Comment 3 Yahor Radtsevich CLA 2011-03-31 15:21:36 EDT
Created attachment 192316 [details]
Stack trace
Comment 4 Yahor Radtsevich CLA 2011-03-31 15:35:23 EDT
Created attachment 192317 [details]
Simple patch

Did not dig deep this bug, but this helps.
Comment 5 Nick Sandonato CLA 2011-03-31 15:56:03 EDT
Hi,

Thanks for your bug report and the patch. While we should probably guard against the case of the null pointer here there is also some initialization of the model that your test cases misses.

In the specific example provided, a lot of the model initialization process has been missed including adding the correct adapters for the ModelQuery. It is this adapter that provides the proper ModelQuery used. Since it's not present, and under most circumstances it would be, you'll get a null ModelQuery.

If you wanted to get everything initialized properly, we use this frequently in our unit tests to get an IDOMModel:

(IDOMModel) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
Comment 6 Yahor Radtsevich CLA 2011-04-01 10:00:07 EDT
Hi Nick,

Thank you for the initialization snippet, it has helped me a lot!

I think this is OK, if the code throws exceptions in the cases when the model is initialized incorrectly.
Comment 7 Nick Sandonato CLA 2011-04-01 11:52:52 EDT
I checked in your changes. Thanks.