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

Bug 331905

Summary: Allow finding Ecore resources even if no ResourceSet given
Product: [Modeling] EMF Reporter: Axel Uhl <eclipse>
Component: Query2Assignee: Project Inbox <emf.query2-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: saurav.sarkar1
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Axel Uhl CLA 2010-12-06 09:59:45 EST
Build Identifier: CVS Head of 2010-12-06

The current EmfHelper implementation fails with an NPE if the QueryContext doesn't provide a valid ResourceSet. Finding Ecore resources through the package registry may, however, still be possible if a new ResourceSetImpl were created in this case. This may be solved using the following patch:

org.eclipse.emf.query2/src/org/eclipse/emf/query2/internal/shared/EmfHelper.java
--- org.eclipse.emf.query2/src/org/eclipse/emf/query2/internal/shared/EmfHelper.java    2010-11-17 11:12:24.686748700 +0100
+++ org.eclipse.emf.query2/src/org/eclipse/emf/query2/internal/shared/EmfHelper
.java   2010-12-06 15:32:55.362157900 +0100
@@ -69,6 +69,8 @@
                        if (rsImpl.getURIResourceMap() == null) {
                                rsImpl.setURIResourceMap(new HashMap<URI, Resource>());
                        }
+               } else if (this.rs == null) {
+                   this.rs = new ResourceSetImpl(); // allows at least for retrieving metamodel URIs
                }
                //              this.createDirtyIndex();
                this.index = index;

Reproducible: Always
Comment 1 saurav sarkar CLA 2010-12-07 00:44:43 EST
Hi Axel,

Thanks for raising it.
I have provided the fix as you mentioned.

I have submitted TestQueryBugs class which provides a test for the above scenario.

Cheers,
Saurav