[
https://issues.apache.org/jira/browse/IO-813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17791013#comment-17791013
]
Miguel Munoz edited comment on IO-813 at 12/1/23 6:31 AM:
----------------------------------------------------------
Actually, the contract for {{{}Comparable{}}}'s {{compareTo()}} method says
this:
The implementor must ensure {{sgn(a.compareTo(b)) == ‑sgn(b.compareTo(a))}} for
all {{a}} and {{{}b{}}}. (This implies that a{{{}.compareTo(b){}}} must throw
an exception iff b{{{}.compareTo(a){}}} throws an exception.)
So the contract actually does allow exceptions, but it puts a constraint on
when they may be thrown. The question becomes whether the class enforces this
{{sgn()}} constraint. (I haven't tried it.)
was (Author: [email protected]):
Actually, the contract for {{{}Comparable{}}}'s {{compareTo()}} method says
this:
The implementor must ensure {{sgn(a.compareTo(b)) == -sgn(b.compareTo(a))}} for
all {{a}} and {{{}b{}}}. (This implies that a{{{}.compareTo(b){}}} must throw
an exception iff b{{{}.compareTo(a){}}} throws an exception.)
So the contract actually does allow exceptions, but it puts a constraint on
when they may be thrown. The question becomes whether the class enforces this
{{sgn()}} constraint. (I haven't tried it.)
> 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)