[
https://issues.apache.org/jira/browse/IO-340?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Feeling Groovy updated IO-340:
------------------------------
Comment: was deleted
(was: Repeats calls to file.exists() does nothingto remedy the false values.
From my own experience on various java versions, on Windows XP and 7 (32 and
64), is that when file.exists() is wrong, that file.length() does in fact
report a non-zero length and correctly report then that the file does in fact
exist.
I found this bug when I was reading and renaming many files and the File object
started providing false exists() values. Like I said, for some reason,
file.exists || file.length()>0 works for me 100% of the time where exists()
failed.
I might suggest not using those file.exists() check and instead construct the
FileInputStream early to catch any FileNotFound error ( to indicate that it
does not exist). Then, the same stream can be used for the actual file
comparison in routines like the contentsEquals functions.
)
> The use of file.exists() is failure prone. Where file.exists() is checked, it
> should be replaced with the following dual check: exists = ( file.exists()
> || file.length()>0 )
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: IO-340
> URL: https://issues.apache.org/jira/browse/IO-340
> Project: Commons IO
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 2.5, 3.x
> Environment: All
> Reporter: Feeling Groovy
> Labels: File, exists, false
> Fix For: 2.5, 3.x
>
> Original Estimate: 24h
> Remaining Estimate: 24h
>
> The use of file.exists() is failure prone. In many cases the jvm can report
> that a file does not exist even when it does. This is due to the caching in
> the operating system.
> Since file.exists() is prone to report false values, a second check can and
> should be made to file.length()>0.
> Where file.exists() is checked, it should be replaced with the following dual
> check:
> A file more reliably exists if: file.exists() || file.length()>0
> Then if the file does not exist, file.length will be 0.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira