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

Bug 143229

Summary: [project explorer] Web DD loading issues during web service indexing
Product: [WebTools] WTP Java EE Tools Reporter: John Lanuti <jlanuti>
Component: jst.j2eeAssignee: Michael D. Elder <mdelder>
Status: CLOSED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: critical    
Priority: P2 CC: cbridgha, danberg, for.work.things, jeffliu, nagrawal, panagiotis.korros, ryman
Version: 1.5   
Target Milestone: 1.5 RC5   
Hardware: PC   
OS: Windows XP   
Whiteboard: PMC_approved
Attachments:
Description Flags
Patches several plugins to drive registration through an extension point
none
port back to 1.4 compliance none

Description John Lanuti CLA 2006-05-23 10:57:25 EDT
Opened for IBM (Daniel Berg) on 0512 WTP:

When I start the workbench with the J2EE perspective open and Web projects in the workspace I get the following exception.

!ENTRY org.eclipse.jst.j2ee.webservice.ui 4 0 2006-05-23 07:52:16.623
!MESSAGE org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'h
ttp://java.sun.com/xml/ns/j2ee' not found. (platform:/resource/DC23Web/WebConten
t/WEB-INF/web.xml, 2, 234)
!STACK 0
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1$DiagnosticWrappedException
: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://j
ava.sun.com/xml/ns/j2ee' not found. (platform:/resource/DC23Web/WebContent/WEB-I
NF/web.xml, 2, 234)
        at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadE
xception(ResourceSetImpl.java:307)
        at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(
ResourceSetImpl.java:268)
        at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(Resou
rceSetImpl.java:390)
        at org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl.ge
tResource(ProjectResourceSetImpl.java:262)
        at org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper.
getOrCreateResource(WorkbenchResourceHelper.java:307)
        at org.eclipse.wst.common.internal.emfworkbench.integration.EditModel.ge
tResource(EditModel.java:688)
        at org.eclipse.wst.common.componentcore.internal.ArtifactEditModel.getRe
source(ArtifactEditModel.java:173)
        at org.eclipse.wst.common.internal.emfworkbench.integration.EditModel.ge
tPrimaryResource(EditModel.java:1516)
        at org.eclipse.wst.common.internal.emfworkbench.integration.EditModel.ge
tPrimaryRootObject(EditModel.java:1497)
        at org.eclipse.wst.common.componentcore.ArtifactEdit.getContentModelRoot
(ArtifactEdit.java:426)
        at org.eclipse.jst.j2ee.internal.webservice.helper.WebServicesManager.ge
tWorkspace14ServiceRefs(WebServicesManager.java:615)
        at org.eclipse.jst.j2ee.internal.webservice.WebServicesNavigatorContentP
rovider.indexWebServices(WebServicesNavigatorContentProvider.java:360)
        at org.eclipse.jst.j2ee.internal.webservice.WebServicesNavigatorContentP
rovider.access$0(WebServicesNavigatorContentProvider.java:345)
        at org.eclipse.jst.j2ee.internal.webservice.WebServicesNavigatorContentP
rovider$WebServiceIndexJob.run(WebServicesNavigatorContentProvider.java:403)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)
Comment 1 John Lanuti CLA 2006-05-25 10:47:08 EDT
*** Bug 142737 has been marked as a duplicate of this bug. ***
Comment 2 Michael D. Elder CLA 2006-05-26 15:12:00 EDT
I am unable to reproduce this error consistently in my local environment. I believe that it related to some sort of timing issue with the parsing of the package registration extensions and the first request of the J2EE schema package. The error does not appear to hinder the further operation of any function, so it does not seem that severe. 

In my local environment, I will normally get the error when my local firewall software blocks the request to load a schema over the network (web_2_4.xsd in this case). Running in Debug seemed to alter the timing or change the behavior enough to hide the error. I don't think I've seen this when running in Debug at all; only when running normally (either from a development image or directly).

Deferring to RC5 as a fix will not be available for RC4.
Comment 3 John Lanuti CLA 2006-06-05 09:53:19 EDT
*** Bug 145100 has been marked as a duplicate of this bug. ***
Comment 4 John Lanuti CLA 2006-06-05 09:54:08 EDT
This is being seen by a number of people.
Comment 5 John Lanuti CLA 2006-06-05 09:56:15 EDT
*** Bug 145140 has been marked as a duplicate of this bug. ***
Comment 6 Michael D. Elder CLA 2006-06-06 10:08:59 EDT
I don't have a proposed fix yet, but here's what I believe is happening:

This problem is a concurrency issue. It's taken some time to debug because the problem is intermittent, occurring somewhere between 25-40% of the time. 

The root of the problem comes in ResourceSetImpl.createResource(URI), where a request is received to load "META-INF/web.xml", *BEFORE* the correct Resource.Factory has been registered. The createResource() method identifies the default global resource factory (ReferencedXMIFactoryImpl) (incorrectly) to create the Web DD resource (as an instance of ReferencedXMIResourceImpl). The correct behavior would be to locate an instance of WebAppResourceFactoryImpl that would then create a WebAppResourceImpl. 

Because the wrong resource type is created, the Resource.load() method tries to use the EMF loading scheme (not the Translators). The resource sits quietly until load is called, when the PackageNotFoundException is thrown. 

It took awhile, but I've determined that the correct ResourceFactory*Registry* is registered correctly, and it doesn't look like the issue is in FileNameResourceFactory.registerLastFileSegment(), although this method is unsynchronized and open to concurrency issues. 

What I've found recently is that the Java initialization tooling trips the load of the org.eclipse.jst.j2ee.web plugin for the JRE contaner defined there (the WebApp Library container), on its Java initialization worker thread. The call:

WebAppResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE);

in WebPlugin.start(BundleContext) is required to properly register the WebAppResourceFactory as the factory for "web.xml" files. 

The JRE container is tripping the load of org.eclipse.jst.j2ee.web plugin on its thread, and apparently before the line above is executed, the WebServicesNavigatorContentProvider's index job (on another thread) requests the "META-INF/web.xml" resource before this call to register can complete. The ResourceSetImpl.createResource() method on the WebServiceNavigatorContentProvider's thread finds no Resource.Factory registered for the "web.xml" segment, and consequently chooses ReferencedXMIResourceFactory as the default. The wrong resource is created, and silently the stage is set for the PackageNotFoundException later on. 
Comment 7 Michael D. Elder CLA 2006-06-06 11:11:31 EDT
The only worthy fix here that I can see is the addition of an internal extension point that would declare:

*the filename short segment (e.g. "web.xml")
*the fully qualified classname of the Resource.Factory for the short segment.

Then the WTPModulesResourceFactory would be re-implemented to take advantage of this extension point, instead of relying on plugin startup to register the file-name, resource factory pairs.
Comment 8 Michael D. Elder CLA 2006-06-06 11:13:43 EDT
"WTPResourceFactoryRegistry", not "WTPModulesResourceFactory". 
Comment 9 Chuck Bridgham CLA 2006-06-06 11:20:44 EDT
After discussing these issues with Michael, we have determined that the
registry scheme that "assumes"  startup order is flawed, and a more direct
registration using extension points is required.

The ResourceFactoryRegistry (WTPResourceFactoryRegistry)  will use an extension
point mechanism that will be checked if no factory has been registered, thus
eliminating any "timing" issues of assumed plugin startup order.

Michael will attach a patch when available.
Comment 10 Michael D. Elder CLA 2006-06-06 15:30:30 EDT
Created attachment 43635 [details]
Patches several plugins to drive registration through an extension point

The patch applies to the following plugins:

org.eclipse.jst.j2ee
org.eclipse.jst.j2ee.core
org.eclipse.jst.j2ee.ejb
org.eclipse.jst.j2ee.web
org.eclipse.jst.j2ee.webservice
org.eclipse.wst.common.emf
org.eclipse.wst.common.modulecore

The patch refactors FileNameResourceFactoryRegistry in org.eclipse.wst.common.emf to be a little more robust in tracking the association between short names and Resource.Factory's. 

A new extension point (for internal use only) is addded to org.eclipse.wst.common.modulecore that declares a registration for short-name to  resource factory pairs. The WTPResourceFactoryRegistry subclass of FileNameResourceFactory is updated to parse this extension point and create mappings in FileNameResourceFactoryRegistry, as if the old plugin.start() semantics were used. 

WTPResourceFactoryRegistry can also log invalid usages for those that are still calling FileNameResourceFactoryRegister.registerLastFileName() directly, rather than through the extension point. 

The package that declares FileNameResourceFactoryRegistry in org.eclipse.wst.common.emf was added as a friend package for the org.eclipse.wst.common.modulecore plugin. The split here had to be made for various reasons, but it was required.

The Descriptor classes (that map short-names to Resource.Factory's) and the ext pt registry reader are coded defensively, so there shouldn't be alot of risk from extensions. 

The remaining plugins required changes to (1) define no-arg constructors for the existing Resource.Factory subclasses and (2) declare the org.eclipse.wst.common.modulecore.resourceFactories extensions to take advantage of the new changes, and (3) remove the programmatic calls from Plugin.start() methods. 

WTPResourceFactoryRegistry will still support programmatic registration for any clients that cannot port, and supports a compile-time flag to turn on warning messages.
Comment 11 Chuck Bridgham CLA 2006-06-06 15:42:58 EDT
Added to PMC for approval....
Comment 12 Larry Isaacs CLA 2006-06-07 16:02:25 EDT
I was reproducing this bug reliably in I200606070737.  In order to do some testing, I built and applied this patch.  An FYI to save a build cycle, Thread.getStackTrace(), used by WTPResourceFactoryRegistry, is new for 1.5.  I substituted "(new Throwable()).getStackTrace()" for "Thread.currentThread().getStackTrace()".  As expected, with the patch I'm no longer reproducing the problem.
Comment 13 Arthur Ryman CLA 2006-06-07 16:29:06 EDT
+1 for WTP 1.5 RC5. 

Testing seems to verify the fix.
Comment 14 Tim Wagner CLA 2006-06-07 16:30:20 EDT
+1 1.5
Comment 15 Michael D. Elder CLA 2006-06-07 17:06:12 EDT
It might be wise (as comment 12 points out) to remove the "Thread.currentThread().getStackTrace() line used to log warnings, if the build is not JRE 1.5 compliant. This was used to provide better context to locate places where programmatic registration was still used. Removing the logging logic will not affect the patch.
Comment 16 John Lanuti CLA 2006-06-07 17:44:52 EDT
Released for WTP 1.5 RC5 060706 driver.
Comment 17 David Williams CLA 2006-06-08 02:43:41 EDT
Created attachment 43835 [details]
port back to 1.4 compliance

Build Breaker #8 ... 
who did not take Michael's advice? 
thread.getStackTrace() 
and 
string.contains 
are not part of JRE 1.4!
Comment 18 John Lanuti CLA 2006-06-08 09:17:55 EDT
You can blame me.  I use 1.4 compliance compiler settings and did not have any errors in my workspace, so that gave me false assurance it was resolved in the patch already.  Thanks David for that catch.
Comment 19 Tim deBoer CLA 2006-06-13 11:24:25 EDT
Bonus round! Who can spot the potential API breakage?

Adopter usage reports show this class is being used by three IBM adopters and one BEA adopter. Running the API scan on the new class doesn't show any problems, but I don't see any indication that it was run either. However, making the constructor private broke at least one of the IBM adopters using this class.

Just a reminder to developers and the PMC that reviewed this change to check for breakage and be very wary of making changes like this late in the cycle. I'll follow up with Jeffrey to figure out why the scan tool isn't working.
Comment 20 Jeffrey Liu CLA 2006-06-14 10:35:01 EDT
The problem is caused by out of date usage reports. After 1.5, I'll get in touch with the adopters regarding how to provide usage reports more often.
Comment 21 John Lanuti CLA 2006-06-16 14:42:14 EDT
Verified on 061606.