| Summary: | EPackage.Registry.INSTANCE.getEPackage(String) returns null after package is initiated. | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Modeling] EMF | Reporter: | Paul Slauenwhite <paulslau> | ||||
| Component: | Core | Assignee: | Dave Steinberg <davidms> | ||||
| Status: | CLOSED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | Ed.Merks, jgwest | ||||
| Version: | 2.5.0 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Bug Depends on: | 270865 | ||||||
| Bug Blocks: | 275576, 276128 | ||||||
| Attachments: |
|
||||||
|
Description
Paul Slauenwhite
Please provide a reproducible test case that I can run myself and then reopen it. I'd also suggest that your debugger works as well as mine and you might even have more time than me to do that. (In reply to comment #1) > Please provide a reproducible test case that I can run myself and then reopen > it. Sure. Steps to reproduce: 1) Import the following project set in an Eclipse 3.5 M7/EMF 2.5 M7/XSD 2.5 M7 installation: <?xml version="1.0" encoding="UTF-8"?> <psf version="2.0"> <provider id="org.eclipse.team.cvs.core.cvsnature"> <project reference="1.0,:pserver:dev.eclipse.org:/cvsroot/tptp,platform/org.eclipse.tptp.platform.models.hierarchy,org.eclipse.tptp.platform.models.hierarchy,HEAD"/> </provider> </psf> 2) Create a plug-in project with a dependency on the org.eclipse.tptp.platform.models.hierarchy plug-in. 3) Create and run the following JUnit plug-in test: import junit.framework.TestCase; import org.eclipse.hyades.models.hierarchy.HierarchyPackage; import org.eclipse.hyades.models.hierarchy.impl.HierarchyPackageImpl; public class ddd extends TestCase { public ddd(String name) { super(name); } public void test1() throws Exception { assertNotNull(HierarchyPackageImpl.init()); SecondThread thread = new SecondThread(); thread.start(); try { Thread.sleep(2000); } catch (InterruptedException i) { //Ignore. } assertNotNull(thread.getHierarchyPackage()); } class SecondThread extends Thread{ public HierarchyPackage hierarchyPackage = null; public void run() { hierarchyPackage = HierarchyPackageImpl.init(); } public HierarchyPackage getHierarchyPackage(){ return hierarchyPackage; } }; } > I'd also suggest that your debugger works as well as mine and you might > even have more time than me to do that. We have already debugged this into the EMF code and we (TPTP) are also resource and time contained. Dave Steinberg provided the following reference and work-around: Reference: http://www.eclipse.org/newsportal/article.php?id=41548&group=eclipse.tools.emf#41548 Work-around: Add the package to registry at the end of the generated org.eclipse.hyades.models.hierarchy.impl.HierarchyPackageImpl.init() method [Thanks Dave for your help in providing this reference.] The question that remains is will this work-around be added to code template for this generated method, assuming it is the correct fix? Note that you should not be calling init() on the package implementation directly. You should simply access the interface's eINSTANCE field. That said, we will make this change in the template. Created attachment 135087 [details]
Updated template and regenerated EMF models
Here's a patch with the template enhancement and all the changes when everything in EMF is regen'ed. In addition to putting the package into the registry at the end of init(), the comment for that method is improved to specify that it shouldn't be called directly by clients.
Ed, does this look good and complete?
(In reply to comment #3) > Note that you should not be calling init() on the package implementation > directly. You should simply access the interface's eINSTANCE field. > > That said, we will make this change in the template. > Correct. This was a shortcut in the JUnit Plug-in test. The fix is in CVS for EMF 2.5. Verified in the EMF 2.5 I200905121800 build. Closing. |