Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341535 - NullPointerException at org.eclipse.wst.xml.core.internal.document.DocumentImpl.getCMAttributes
Summary: NullPointerException at org.eclipse.wst.xml.core.internal.document.DocumentIm...
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Nick Sandonato CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-31 15:15 EDT by Yahor Radtsevich CLA
Modified: 2011-04-01 11:53 EDT (History)
2 users (show)

See Also:


Attachments
JUnit for the bug (1.50 KB, application/octet-stream)
2011-03-31 15:17 EDT, Yahor Radtsevich CLA
no flags Details
JUnit for the bug (as plain text) (1.50 KB, text/plain)
2011-03-31 15:18 EDT, Yahor Radtsevich CLA
no flags Details
Stack trace (4.79 KB, text/plain)
2011-03-31 15:21 EDT, Yahor Radtsevich CLA
no flags Details
Simple patch (730 bytes, patch)
2011-03-31 15:35 EDT, Yahor Radtsevich CLA
nsand.dev: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.