JSR199 FileObjects don't obey general contract of equals.

Peter Ahé peter at ahe.dk
Wed Jun 20 23:20:41 PDT 2007

On 6/20/07, Jonathan Gibbons <Jonathan.Gibbons at sun.com> wrote:
> On Jun 20, 2007, at 10:49 PM, Peter Ahé wrote:
> > On 6/20/07, Jonathan Gibbons <Jonathan.Gibbons at sun.com> wrote:
> >> So the proposal is the following
> >> - fix ZipFileObject equality to use && not ||
> >
> > That may fix the hashCode issue, but are you sure "foo" and its
> > absolute equivalent will remain equal?
> >
> That's why I added the 2 bullet in the list -- these were a set to be
> taken together,
> not alternatives; sorry if that was not clear.

Oh, I mistook it for RegularFileObject.  I guess I skimmed the second
part.  ZipFileObject.equals is clearly broken.  Ignoring that issue,
and focusing on only one thing at a time: I think you need to use
getCanonicalFile in RegularFileObject.  However, you may want to
consider wrapping it in:

File safeGetCanonicalFile(File f) {
           try {
               return f.getCanonicalFile();
           } catch (IOException e) {
               return f.getAbsoluteFile();

And you may want to ensure this is only calculated once per file
object.  However, you must keep the user specified file name around.
Otherwise, diagnostics gets messed up.


More information about the compiler-dev mailing list