Bug 214731 - [batch][compiler] ClasspathJar#getPath does not honor its contract
Summary: [batch][compiler] ClasspathJar#getPath does not honor its contract
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.4 M5   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-09 05:27 EST by Maxime Daniel CLA
Modified: 2008-02-04 07:36 EST (History)
2 users (show)

See Also:
kent_johnson: review+


Attachments
Fix + test cases (8.23 KB, patch)
2008-01-11 05:43 EST, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2008-01-09 05:27:28 EST
Source based, circa v_831 (present since mid 2005 at least)

ClasspathJar#getPath overrides FileSystem#getPath which is expected to return an absolute path. Not so. Running the batch compiler with parameters '-cp lib.jar X.java' leads to getPath returning 'lib.jar'.

Found this out while investigating bug 97332. While the fastest cure would probably be to fix the comment (this is an internal package anyway), I believe we should examine carefully whether we want to respect the contract or to amend it, and to examine the implications in other parts of the code. Hence this bug.
Comment 1 Maxime Daniel CLA 2008-01-11 04:49:13 EST
First exploration raises the following comments:
- ClasspathDirectory, a sibling class of ClasspathJar, honors the contract; this would support aligning the implementation with the API;
- the same class caches the path, whereas ClasspathJar only caches the normalized path; for reasons of homogeneity, I'd rather cache both in all cases (the impact does not seem too heavy);
- ClasspathJar#normalizedPath suffers the same bug as ClasspathJar#getPath.

Will craft a fix that caches path and normalizedPath as absolute paths in all cases.
Comment 2 Maxime Daniel CLA 2008-01-11 05:29:15 EST
Note also that:
- we use absolute paths, which may be different from canonical paths on certain
  platforms; but this is what is documented, hence it should be fine;
- ClasspathJar is more prone to white-box testing than ClasspathDirectory, which
  constructor is not public; I won't change the visibility for the sole benefit of
  whitebox testing though;
- normalizedPath also replaces exotic File separator by '/' for all 
  implementations, which is not clear from the doc; my patch refines the doc in
  this respect.
Comment 3 Maxime Daniel CLA 2008-01-11 05:43:32 EST
Created attachment 86658 [details]
Fix + test cases
Comment 4 Maxime Daniel CLA 2008-01-11 06:47:28 EST
Kent, would you please tell me what you think?
Comment 5 Kent Johnson CLA 2008-01-11 13:11:23 EST
looks simple enough
Comment 6 Maxime Daniel CLA 2008-01-14 03:27:47 EST
Released for 3.4 M5.
Comment 7 Eric Jodet CLA 2008-02-04 07:36:17 EST
Verified for 3.4M5 using build I20080204-0010