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

Bug 321175

Summary: ClassCastException: PassthruResourcesEList incompatible with SynchronizedResourcesEList
Product: [WebTools] WTP Java EE Tools Reporter: Carl Anderson <ccc>
Component: jst.jemAssignee: Carl Anderson <ccc>
Status: RESOLVED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: blocker    
Priority: P3 CC: david_williams, deboer, jsholl, kaloyan, raghunathan.srinivasan
Version: 3.2Flags: david_williams: pmc_approved+
deboer: pmc_approved?
ccc: pmc_approved? (naci.dai)
deboer: pmc_approved+
ccc: pmc_approved? (neil.hauge)
kaloyan: pmc_approved+
ccc: review+
Target Milestone: 3.2.1   
Hardware: PC   
OS: Windows XP   
Whiteboard: PMC_approved
Bug Depends on: 319772    
Bug Blocks:    
Attachments:
Description Flags
Check the type before casting none

Description Carl Anderson CLA 2010-07-28 16:05:14 EDT
An adopter is hitting the following exception:

java.lang.ClassCastException: org.eclipse.wst.common.internal.emfworkbench.PassthruResourceSet$PassthruResourcesEList incompatible with org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl$SynchronizedResourcesEList

This happens in ProjectResourceSetImpl.getImmutableResources() - bug 319772 changed it so that the the EList returned from getResources() is cast to a SynchronizedResourcesEList.  The problem is that classes that extend ProjectResourceSetImpl (like PassthruResourceSet) can return a different type of EList in their override of getResources().
Comment 1 Carl Anderson CLA 2010-07-28 16:07:30 EDT
Another part of the proper fix- there is no reason why PassthruResourceSet's PassthruResourcesEList cannot extend SynchronizedResourcesEList.  In fact, it gains a lot of benefits by doing so.  However, since we cannot guarantee that all extenders of ProjectResourceSetImpl will return an implementation of SynchronizedResourcesEList, we need to check the type in getImmutableResources().
Comment 2 Carl Anderson CLA 2010-07-28 16:08:36 EDT
Created attachment 175442 [details]
Check the type before casting
Comment 3 Carl Anderson CLA 2010-07-28 16:18:05 EDT
To be clear, in WTP 3.2.1, two methods in EMFWorkbenchEditPlugin, createIsolatedresourceSet() and createWorkspacePassthruResourceSet(), now return ResourceSets that will cause this ClassCastException.  There is no workaround.
Comment 4 Carl Anderson CLA 2010-07-29 11:26:25 EDT
The exposure of this to end users:

If an adopter product attempts to load a resource based off of a PassthruResourceSet, it will get this ClassCastException and prevent the resource from being loaded.

This will appear to the user as an empty resource, whereas there may have been a resource to load.

Furthermore, this is an exception that is not caught by our code.  Thus a dialog may be surfaced to the end user with this exception, or it may just be caught and logged.
Comment 5 Carl Anderson CLA 2010-07-29 11:50:03 EDT
Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 

As noted before, this causes ResourceSets that were previously supported/working (including PassthruResourceSet in WTP) from being able to load resources.  In the adopter case, this will keep proprietary extensions and mappings associated with common Java EE modules (especially EJBs) from loading.  This effects manipulation of the projects, including deploying them on proprietary servers (since the necessary extension and mapping information is not loaded).

Is there a work-around? If so, why do you believe the work-around is insufficient? 

There is no workaround.

How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 

This has been tested by hand and by providing a quick test fix that the adopter product has tested.

Give a brief technical overview. Who has reviewed this fix?

The fix consists of two parts:  Checking the class of the EList before casting, and updating PassthruResourceSet to use a SynchronizedResourcesEList for its resources.  (Note that that is not a new class - SynchronizedResourcesEList was added in WTP 3.0.x to help protect the resource set from ConcurrentModificationExceptions.  PassthruResourceSet will benefit from that additional protection.)
Neeraj Agrawal has reviewed this fix.

What is the risk associated with this fix?

This is a relatively low risk fix, but it is in a high-usage and high-importance area.  (As can be seen by the "simple" change in bug 319772 that broke this.)
Comment 6 Carl Anderson CLA 2010-07-29 12:00:58 EDT
For the record, Chuck is on vacation, and I am his delegate for these matters until his return on 8/4.
Comment 7 Kaloyan Raev CLA 2010-07-29 12:07:04 EDT
Looks like a completely safe patch.
Comment 8 David Williams CLA 2010-07-29 12:26:05 EDT
Unfortunately a very serious regression for adopter product/function. While wouldn't appear in WTP all by itself, I'd prefer to fix this for 3.2.1 rather than build an immediate patch. 

I'm not sure, though, under what conditions other adopters might hit this same problem, if/when they begin to pick up this service release? 

I think this last minute respin is feasible, but only because we are not part of a "simultaneous release" stack for this off-cycle maintenance ... though any rebuild this last minute introduces risk and logistical problems. (e.g. we'll have to re-mirror build distribution and repository).
Comment 9 Carl Anderson CLA 2010-07-29 16:12:27 EDT
Committed to HEAD for WTP 3.2.1 and WTP 3.3