harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Regis Xu (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-6198) [java6][classlib][sql] Timestamp.compareTo returns incorrect result
Date Fri, 08 May 2009 02:41:46 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-6198?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707213#action_12707213
] 

Regis Xu commented on HARMONY-6198:
-----------------------------------

Yes Java 6 spec doesn't mention "Throws: ClassCastException" in "Throws section, but it explicitly
says
"Compares this Timestamp object to the given Date, which must be a Timestamp  object. If the
argument is not a Timestamp object, this method throws a ClassCastException object."

So I'm confused if Timestamp.compareTo(Date) can't accept Date object, Why we need this method,
Timestamp.compareTo(Timestamp) is just enough.

RI 1.5.0_06 throws but 1.5.0_07 does not, seems like a bug fix in RI :)

> [java6][classlib][sql] Timestamp.compareTo returns incorrect result
> -------------------------------------------------------------------
>
>                 Key: HARMONY-6198
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6198
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M9
>            Reporter: Jim Yu
>         Attachments: HARMONY-6198.diff
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> I found Timestamp.compareTo(Date) would return 1 even when both the timestamp and date
object are constructed with the same millisecond values. There is testcase below. I've made
a fix to solve the problem.
> import java.sql.Timestamp;
> import java.util.Date;
> public class TimeStampComp {
>     /**
>      * @param args
>      */
>     public static void main(String[] args) {
>         long time = System.currentTimeMillis();
>         Date date = new Date(time);
>         Timestamp timestamp = new Timestamp(date.getTime());
>         System.out.println("compareTo returns " + timestamp.compareTo(date));
>     }
> }
> Result of RI:
> compareTo returns 0
> Result of Harmony:
> compareTo returns 1

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message