[
https://issues.apache.org/jira/browse/IO-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17791043#comment-17791043
]
Elliotte Rusty Harold commented on IO-813:
------------------------------------------
That's a surprise. Looking at
https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html I find
"Finally, the implementor must ensure that x.compareTo(y)==0 implies that
sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z. " but I do not see "This
implies that x.compareTo( y ) must throw an exception iff y.compareTo( x )
throws an exception." Was that added in a later version? If so, which?
In fact, it looks like it was. Java 11 API docs do contain the text you cite:
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Comparable.html
Even in Java 11, I think throwing an UncheckedIOException here is a bad idea.
> 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)