Bug 264776 - ExternalPackageFragmentRoot does not expose its content consistently
Summary: ExternalPackageFragmentRoot does not expose its content consistently
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-12 16:09 EST by Sebastian Zarnekow CLA
Modified: 2011-01-25 11:16 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Zarnekow CLA 2009-02-12 16:09:07 EST
We introduced a classpath-uri-scheme in Xtext to refer to EMF-resources. In Xtext's standalone mode, we use a classloader to resolve these URIs, in runtime mode, we rely on the jdt to obtain resources via IJavaProject#getAllPackageFragmentRoots and friends.

However, sometimes we face the problem, that an ExternalPackageFragmentRoot returns a resource from ExternalPackageFragmentRoot#resource() that does not return valid members from IFolder#findMember, even if they exist (at least in the filesystem). This problem occures, if we create an IJavaProject with contents in a ui-wizard and try to resolve a classpath-uri, when the java tooling is not yet fully initialized.

The workaround, that we came up with, is to fall back to the File-API instead of relying on the Resource-API in these rare cases.

The bug seems to be, that ExternalPackageFragmentRoot should not return from resource() when it cannot return an instance, that works as expected.

see http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.tmf/org.eclipse.xtext/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/util/JdtClasspathUriResolver.java?root=Modeling_Project&view=markup for a pointer to the code, that fails during javacore initialization
Comment 1 Sebastian Zarnekow CLA 2010-01-05 10:48:44 EST
Please note that the referenced class has been rewritten since Feb 2009.
Comment 2 Jay Arthanareeswaran CLA 2010-12-14 06:11:40 EST
(In reply to comment #0)
> The bug seems to be, that ExternalPackageFragmentRoot should not return from
> resource() when it cannot return an instance, that works as expected.

Are you saying it should not cache the "this.resource" or that the method should wait until it can find a valid resource? 

> the filesystem). This problem occures, if we create an IJavaProject with
> contents in a ui-wizard and try to resolve a classpath-uri, when the java
> tooling is not yet fully initialized.

I know it's been a while since you reported this bug, but a test case or a detailed steps will help.
Comment 3 Sebastian Zarnekow CLA 2010-12-14 08:00:35 EST
(In reply to comment #2)
> I know it's been a while since you reported this bug, but a test case or a
> detailed steps will help.

As we successfully use a workaround since the early days of Helios, I'm not sure that I can reproduce this issue.

This is the code that we use now:

										// the following code will return null
// IResource resource = packageFragmentRoot.getUnderlyingResource();
if (!(packageFragmentRoot instanceof ExternalPackageFragmentRoot))
  throw new IllegalStateException();
IResource resource = ((ExternalPackageFragmentRoot)packageFragmentRoot).resource();


Well, I'm not that familiar with the semantics of #getUnderlyingResource() but shouldn't it return the very same instance as the internal #resource() method?
Comment 4 Jay Arthanareeswaran CLA 2010-12-15 02:58:04 EST
(In reply to comment #3)
> Well, I'm not that familiar with the semantics of #getUnderlyingResource() but
> shouldn't it return the very same instance as the internal #resource() method?

For external elements, such as ExternalPackageFragmentRoot and JarPackageFragmentRoot pointing at an external JAR, the underlying resource is null. Please refer to the documentation - IJavaElement#getResource() and IJavaElement#getUnderlyingResource()
Comment 5 Sebastian Zarnekow CLA 2011-01-03 04:18:44 EST
(In reply to comment #4)
> Please refer to the documentation - IJavaElement#getResource() and
> IJavaElement#getUnderlyingResource()

Well from the docs it's still not clear to me why ExternalPackageFragmentRoot#getUnderlyingResource returns null and why "An external package fragment root never has an associated resource." while the internal #resource() returns the information that I need. Is it really necessary to convert the #getPath by myself?
Comment 6 Jay Arthanareeswaran CLA 2011-01-04 04:55:45 EST
(In reply to comment #5)
> Well from the docs it's still not clear to me why
> ExternalPackageFragmentRoot#getUnderlyingResource returns null and why "An
> external package fragment root never has an associated resource." while the
> internal #resource() returns the information that I need. Is it really
> necessary to convert the #getPath by myself?

In the case of external package fragment root, what the #resource returns is the resource representing the linked folder in the hidden external folder's project. It doesn't really return the underlying resource as such since it's not contained in the workspace. So, I think it makes sense we keep it the way it is now.
Comment 7 Sebastian Zarnekow CLA 2011-01-04 04:59:40 EST
Agreed.
Comment 8 Jay Arthanareeswaran CLA 2011-01-06 23:04:37 EST
Closing this.
Comment 9 Olivier Thomann CLA 2011-01-25 11:16:08 EST
Verified.