commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Feeling Groovy (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (IO-340) 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 )
Date Sat, 13 Oct 2012 12:28:03 GMT

     [ 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: The bug is known:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5003595

Because of file system complications, it cannot be fixed and the user if left to sort it out.

However, when I use FileUtils.contentsEquals(filea,fileb) it does file.exists internally as
preliminary comparisons.
.. and then it produces erratic behaviour.

Took me a while to figure our why my backups were not working and it was this bug. There are
lots of other links on the web about this same bug:

http://stackoverflow.com/questions/3833127/alternative-to-file-exists-in-java
http://www.coderanch.com/t/369040/java/java/java-io-File-exists-bug


Cheers,
Wilf)
    
> 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

Mime
View raw message