Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 95441D7B7 for ; Sun, 5 Aug 2012 04:27:08 +0000 (UTC) Received: (qmail 4487 invoked by uid 500); 5 Aug 2012 04:27:08 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 4044 invoked by uid 500); 5 Aug 2012 04:27:04 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 4002 invoked by uid 99); 5 Aug 2012 04:27:02 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Aug 2012 04:27:02 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id 91A13142823 for ; Sun, 5 Aug 2012 04:27:02 +0000 (UTC) Date: Sun, 5 Aug 2012 04:27:02 +0000 (UTC) From: "Wilf Middleton (JIRA)" To: issues@commons.apache.org Message-ID: <1618444028.14499.1344140822600.JavaMail.jiratomcat@issues-vm> In-Reply-To: <1522353212.11775.1344022502756.JavaMail.jiratomcat@issues-vm> Subject: [jira] [Commented] (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 ) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/IO-340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13428795#comment-13428795 ] Wilf Middleton commented on IO-340: ----------------------------------- More proof for Murphy's Law. > 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: Wilf Middleton > 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: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira