Community
Participate
Working Groups
Build Identifier: wtp-sdk-R-3.2.3-20110217214612 As part of the edit model used for our editor (which is an extension of org.eclipse.wst.common.internal.emfworkbench.integration.EditModel), there is an instance of the org.eclipse.wst.common.internal.emfworkbench.integration.ResourceSetWorkbenchEditSynchronizer class attached to the edit model. When resources are deleted and then saved in our editor, the method ResourceSetWorkbenchEditSynchronizer.getResources(IFile aFile) is called to determine which resources to unload from the resource set. It does this by comparing the URI of the IFile passed in to the resources in the resource set. The method code is this: protected List getResources(IFile aFile) { List resources = new ArrayList(); List allResources = resourceSet.getResources(); for (Iterator iterator = allResources.iterator(); iterator.hasNext();) { Resource res = (Resource) iterator.next(); URI resURI = res.getURI(); String resURIString = ""; //$NON-NLS-1$ if (resURI.path() != null) { IPath resURIPath; if (WorkbenchResourceHelper.isPlatformResourceURI(resURI)) resURIPath = new Path(URI.decode(resURI.path())).removeFirstSegments(2); else resURIPath = new Path(URI.decode(resURI.path())).removeFirstSegments(1); resURIString = resURIPath.toString(); } if (!resURIString.equals("") && aFile.getFullPath().toString().indexOf(resURIString) != -1) //$NON-NLS-1$ resources.add(res); } return resources; } The problem here is the last test in the loop which is doing this: if (!resURIString.equals("") && aFile.getFullPath().toString().indexOf(resURIString) != -1) The problem is the use of 'indexOf' here. This is incorrect. An 'equals' call should be used here as using 'indexOf' will match similarly named resources and unload them from the resource set. This erroneous unloading then causes our editor to behave erratically as many NPEs are hit as the 'eResource()' call on the resource in the resource set now returns a null value when it still should be loaded in the resource set. The code should be like this: if (!resURIString.equals("") && aFile.getFullPath().toString().equals(resURIString)) //$NON-NLS-1$ Here are some examples: IFile passed in: aFile.getFullPath().toString() == Export1.export URI in resSet == Export1.exportex This will match even thought the file extensions are different. aFile.getFullPath().toString() == SCAExport1.export URI in resSet == Export1.export This will match even thought the file names are different. Reproducible: Always
Created attachment 192128 [details] Proposed fix to avoid resources incorrectly unloaded
Created attachment 198133 [details] This patch contains a better fix for this defect
Committed to R3_2_maintenance for WTP 3.2.5.
Committed to HEAD for WTP 3.3.1 and WTP 3.4.0