32

Every time I call IJavaProject.findPackageFragmentRoots(IClasspathEntry cpe) and pass it an IClasspathEntry of kind CPE_PROJECT, it returns an empty list. I paused the debugger and ran the following lines in the Eclipse Display view to see what was going on:

IClasspathEntry cpe = javaProject.getRawClasspath()[8];
cpe.toString();
    (java.lang.String) /Some Project[CPE_PROJECT][K_SOURCE][isExported:false][combine access rules:false]

// Show that the referenced project exists and has a root containing source
IClasspathEntry cpe = javaProject.getRawClasspath()[8];
IProject someProject = ResourcesPlugin.getWorkspace().getRoot().getProject(cpe.getPath().toString());
IJavaProject someJavaProject = (IJavaProject) someProject.getNature(JavaCore.NATURE_ID);
IPackageFragmentRoot pfr = someJavaProject.getPackageFragmentRoots()[0];
new Boolean(pfr.getKind() == IPackageFragmentRoot.K_SOURCE).toString();
    (java.lang.String) true

IClasspathEntry cpe = javaProject.getRawClasspath()[8];
javaProject.findPackageFragmentRoots(cpe);
    (org.eclipse.jdt.core.IPackageFragmentRoot[]) []

The classpath entry is part of the Java project's classpath and it's of kind CPE_PROJECT. In addition, the referenced Java project (titled "Some Project") has at least one root containing source. According to the javadoc for IJavaProject, it seems this should return at least one IPackageFragmentRoot, but its doesn't.

Any idea what I'm misunderstanding here? How can I get the IPackageFragmentRoots from an IClasspathEntry of kind CPE_PROJECT without doing something hackish? (I mean, I could get the IJavaProject from the classpath entry and iterate through its raw classpath, ignoring non-exported entries, in search of IPackageFragmentRoots.)

3
  • 3
    A bug has been filed: bugs.eclipse.org/bugs/show_bug.cgi?id=324367
    – peskal
    Commented Sep 5, 2010 at 4:45
  • 8
    the bug has been fixed. Did it fix your problem? Commented May 11, 2011 at 20:12
  • If the problem is now fixed, please post self-answer and accept so this can be closed :)
    – user166390
    Commented Jul 13, 2011 at 5:04

1 Answer 1

0

This was a bug that was fixed in Eclipse 3.7 (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=324367).

As per the new API:

The result does not include package fragment roots in other projects referenced on this project's classpath.

See http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/IJavaProject.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.