Bug 276373 - Incorrect resource comparison with IJavaProject.isOnClasspath(IResource)
Summary: Incorrect resource comparison with IJavaProject.isOnClasspath(IResource)
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.5.1   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 276707
  Show dependency tree
 
Reported: 2009-05-14 15:50 EDT by Paul Fullbright CLA
Modified: 2010-05-27 17:35 EDT (History)
5 users (show)

See Also:
srikanth_sankaran: review+


Attachments
test project (8.20 KB, application/zip)
2009-06-10 16:45 EDT, Paul Fullbright CLA
no flags Details
junit test plugin (5.28 KB, application/zip)
2009-06-10 16:53 EDT, Paul Fullbright CLA
no flags Details
Proposed patch (4.78 KB, patch)
2009-06-16 05:53 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Modified patch (5.22 KB, patch)
2009-06-24 01:01 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Patch with updated tests (5.85 KB, patch)
2009-06-24 01:35 EDT, Jay Arthanareeswaran CLA
srikanth_sankaran: iplog+
srikanth_sankaran: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Fullbright CLA 2009-05-14 15:50:34 EDT
When asking a java project whether a jar project resource is on the classpath, I pass in a project resource (/FooProject/WebContent/WEB-INF/lib/foo.jar), and it is compared to the same resource in the web app library container, only there it is absolutely named (C:/dev/workspaces/MyWorkspace/FooProject/WebContent/WEB-INF/lib/foo.jar).  This is the exact same resource, but the workspace path is being compared to the absolute path.  Can absolute paths not be used in both cases?
Comment 1 Srikanth Sankaran CLA 2009-05-27 01:37:01 EDT
Jay, can you please investigate this ?
Comment 2 Jay Arthanareeswaran CLA 2009-05-27 04:35:20 EDT
Could you please tell me how you added the jar file to the project (classpath)
- whether as a project resource or as an external jar file? My observation is
that when you add a library as an external jar to a project (even though it's
inside the project) the absolute path is being used. On the other hand if you
add the jar as a project resource, which is the recommended way, then this
comparison failure should disappear.
Comment 3 Paul Fullbright CLA 2009-05-27 10:19:57 EDT
In the particular scenario where I discovered this, I was using the "Web App Libraries" library container provided by WTP, wherein all jars that are added to the WebContent/WEB-INF/lib directory are automatically added to the library container.  This is of course a WTP implementation.  The external jars method is the easiest to reproduce from a pure-JDT standpoint.

As an addition, I'd like to mention that these aren't *my* projects I'm dealing with here.  If they were, it would be easy to use the recommended way you suggest.  I'm dealing with user projects (I develop for WTP as well) and so I am required to use whatever setting the user has, whether it's recommended or not.
Comment 4 Jay Arthanareeswaran CLA 2009-05-28 06:56:27 EDT
Hi Paul,

I tried with a simple web application and could not reproduce the problem. This is what I did:
1. Created a simple dynamic web project.
2. Added few jar files to the WEB-INF folder.
3. Ensured that the jars were added to the 'Web App Libraries'
4. Open the 'Configure Build path' and open 'Web App Libraries' and ensure that the jar files are added with the workspace path and NOT absolute path.
5. Apart from this, I also stepped in to the JavaProject#isOnClasspath, I could find only the workspace paths being used.

Please let me know if these are the right steps to reproduce the problem. Else, may I request you to provide me some test case, preferably the project with which you are finding the bug?
-Jay
Comment 5 Jay Arthanareeswaran CLA 2009-06-02 02:45:12 EDT
Alright, I misunderstood the problem statement. So, I guess what Paul wants is the ability to compare a relative path with an absolute path and vice versa. And this seems more like an enhancement to me.

Jerome, can you please let me know your take on this one?
Comment 6 Paul Fullbright CLA 2009-06-02 10:27:00 EDT
That's not *entirely* correct.  My problem (among other things) is that I can't control whether I use a relative or absolute path.  The project resource always has a relative path.  The classpath entry *usually* has an absolute path.

I iterate through jars in my project.  Those resources are always relative paths.  I ask "is this jar resource on the project classpath?"  The framework returns false, because the classpath entry is using an absolute path for the jar.  But in fact, the jar resource *is* on the project classpath.  *It's the exact same jar.*  Relative or absolute, this method is returning an incorrect answer.

And I'm working on a test case but haven't completed it just yet, but I do not get the same results as Jayaprakash.  The classpath entries for web app libraries use absolute paths.

Comment 7 Jerome Lanneluc CLA 2009-06-02 13:14:54 EDT
Jay, one way to fix this issue would be to store a workspace relative path in the resolved classpath field (see PerProjectInfo) for paths that are given as absolute paths (either in the raw classpath or the container's classpath) but that are in fact relative.
Comment 8 Jay Arthanareeswaran CLA 2009-06-03 06:51:01 EDT
Paul,
I understand the issue better now. However, I would really like to have the test case that you mentioned. Though I can see the issue somewhat in the case of external jar files, they are not really same because your issue arises when you use classpath containers. So, please share the test case once ready.
Comment 9 Paul Fullbright CLA 2009-06-10 16:45:02 EDT
Created attachment 138852 [details]
test project

This project is for use with the following test.  Simply put in your JUnit target workspace and adjust the following:
- the classpath entry for the external library jar should match your directory structure
- add a classpath variable VARIABLE_LIB that points to the variableLib.jar
- add a user library USER_LIB that includes the userLib.jar
Comment 10 Paul Fullbright CLA 2009-06-10 16:53:51 EDT
Created attachment 138853 [details]
junit test plugin

Contains one JUnit test class:  Test.

My results:
testSimple - pass
testInternalJar - pass
testExternalJar - fail
testVariableJar - fail
testUserLibraryJar - pass (I was surprised!  But the user library setup figures
   out that the jar being added is an internal resource.)
testWebAppLibJar - fail


Note that while I did explicitly name the path to each jar in the tests, if I'd simply iterated through the project files to find the correct IFile, they'd be identical (or as identical as handles get).
Comment 11 Jay Arthanareeswaran CLA 2009-06-16 05:53:17 EDT
Created attachment 139273 [details]
Proposed patch

Path includes a check to compare the absolute path of a resource when the classpath entry is an absolute path. Test cases included.
Comment 12 Paul Fullbright CLA 2009-06-16 15:11:51 EDT
This patch works for my test cases, but I've uncovered a related issue (documented in bug 280497).

We can treat these as separate issues if that's fine with JDT.
Comment 13 Srikanth Sankaran CLA 2009-06-22 02:47:04 EDT
(In reply to comment #11)
> Created an attachment (id=139273) [details]
> Proposed patch
> Path includes a check to compare the absolute path of a resource when the
> classpath entry is an absolute path. Test cases included.

Does org.eclipse.jdt.internal.core.JavaProject.isOnClasspathEntry(IPath, boolean, boolean, IClasspathEntry) need a similar change ? This is a
private method that but gets called from public API method
org.eclipse.jdt.internal.core.JavaProject.isOnClasspath(IJavaElement)
Comment 14 Jay Arthanareeswaran CLA 2009-06-24 01:01:31 EDT
Created attachment 139944 [details]
Modified patch

Attaching the modified patch. The JavaProject#isOnClasspathEntry also needs similar fix.
Comment 15 Jay Arthanareeswaran CLA 2009-06-24 01:35:55 EDT
Created attachment 139945 [details]
Patch with updated tests

Updated the patch after the fixes to the JavaProject#isOnClasspathEntry.
Comment 16 Srikanth Sankaran CLA 2009-06-24 04:28:29 EDT
Released Jay's fix in HEAD for 3.6M1
Comment 17 Paul Fullbright CLA 2009-07-07 10:35:39 EDT
This and bug 280497 are blocking one of our milestone targeted bugs.  Can this fix possibly be moved to maintenance?
Comment 18 Srikanth Sankaran CLA 2009-07-08 03:32:04 EDT
(In reply to comment #17)
> This and bug 280497 are blocking one of our milestone targeted bugs.  Can this
> fix possibly be moved to maintenance?

Olivier, what do you think ?

Comment 19 Olivier Thomann CLA 2009-07-13 17:08:58 EDT
Blocking Dali JPA Tools is not an option.
Please backport for 3.5.1.

Reopening to get it fixed for 3.5.1.
Comment 20 Srikanth Sankaran CLA 2009-07-14 06:59:07 EDT
Fix backported and released to R3_5_maintenance branch.
Comment 21 Frederic Fusier CLA 2009-08-04 04:27:22 EDT
Verified for 3.6M1 using I20090802-2000
Comment 22 Paul Fullbright CLA 2009-08-11 12:01:21 EDT
I have verified the fix for 3.6 M1 and 3.5 maintenance build M20090807-0800.