[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    [jira] [Commented] (IO-813) LastModifiedFileComparator should not throw exceptions, period
From:       "Elliotte Rusty Harold (Jira)" <jira () apache ! org>
Date:       2023-11-30 20:56:00
Message-ID: JIRA.13552553.1696114143000.29499.1701377760037 () Atlassian ! JIRA
[Download RAW message or body]


    [ https://issues.apache.org/jira/browse/IO-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17791779#comment-17791779 \
] 

Elliotte Rusty Harold commented on IO-813:
------------------------------------------

Interesting. The Javadoc doesn't show IOException for File.lastModified, which is \
strange but this goes back to Java  1.0. Instead it returns 0 on I/O error, though \
that is still potentially inconsistent since this method accesses the file system. It \
is not simply returning a value from the object. Accesses to the file system are not \
reliable. Both race conditions and outright failures can happen here. 

However this comparator doesn't call File.lastModified(). It calls \
Files.getLastModifiedTime and that method does throw an IOException when something \
goes wrong here. 

> LastModifiedFileComparator should not throw exceptions, period
> --------------------------------------------------------------
> 
> Key: IO-813
> URL: https://issues.apache.org/jira/browse/IO-813
> Project: Commons IO
> Issue Type: Bug
> Reporter: Elliotte Rusty Harold
> Priority: Major
> 
> LastModifiedFileComparator is likely broken by design since it can unexpectedly \
> throw UncheckedIOException. This violates the contract of Comparable.compareTo \
> which is not documented to throw that exception.  I analyzed almost this exact case \
> in detail here: https://medium.com/@elharo/when-you-cant-throw-an-exception-b9f9b0db9ba4
>  I'm not sure how to fix this now, but I'm tempted to simply deprecate this entire \
> class.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic