JDK-6572968 : equals and hashcode incorrect for file objects returned from StandardFileManager
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2007-06-22
  • Updated: 2010-04-03
  • Resolved: 2010-01-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description
The definition of equality is unspecified for file objects returned from StandardJavaFileManager, and the current implementatio is inconsistent and incorrect.

We should specify the behavior and fix the implementation.

Comments
EVALUATION The behavior of RegularFileObject.equals tries to compare the results of using getCanonicalFile, and returns false in the case of IOExceptions. This is inconsistent with hashcode, and can lead to incorrect results in the case of network error (i.e when getCanonicalFile throws an exception.) In order to reliably satisfy the general contract of hashcode and equals, RegularFileObject should use getAbsoluteFile, not getCanonicalFile. The downside is that this will not take symbolic links into account. This can be mitigate by the use of the existing isSameFile method on StandardJavaFileManager. For ZipFileObject, it tries to compare the ZipFile and the path within the zip file. It gets this wrong by using || instead of &&. That aside, it currently checked for reference equality of the ZipFile objects; it should really use the same semantics as for RegularFileObject -- ie. it should use File.getAbsolutePath() when determining whether two ZipFileObjects are equal, and hashcode should match.
22-06-2007