harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Luht (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-923) Incorrect dates in java.util.Calendar() when year is very large
Date Wed, 19 Jul 2006 13:09:13 GMT
Incorrect dates in java.util.Calendar() when year is very large
---------------------------------------------------------------

                 Key: HARMONY-923
                 URL: http://issues.apache.org/jira/browse/HARMONY-923
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
         Environment: Windows XP professional
            Reporter: Anton Luht
            Priority: Minor


VM + classlib revision 423073

Problem: with large values of year (aroung Integer.MIN_VALUE and Integer.MAX_VALUE) dates
returned by Calendar diff from RI. The following test case shows it:

import java.util.*;

public class Test  { 
    public static void main (String[] args) {   
          Calendar cal = Calendar.getInstance();

          int year = Integer.MIN_VALUE + 71;
          cal.setTimeZone(TimeZone.getTimeZone("GMT"));
          cal.set(Calendar.YEAR, year + 1900);
          cal.set(Calendar.MONTH, Calendar.JANUARY);
          cal.set(Calendar.DATE, 1);
          cal.set(Calendar.HOUR_OF_DAY, 0);
          cal.set(Calendar.MINUTE, 0);
          cal.set(Calendar.SECOND, 0);
          cal.set(Calendar.MILLISECOND, 0);

          System.out.println(cal.getTimeInMillis());
    }
}

Output in RI: 
6017546357372606464

Output in Harmony:
61................................

The problem is that though private method of GregorianCalendar daysFromBaseYear(int year)
returns long, its argument is int and things like 'year - 1970' can cause int overflow. The
solution is to cast argument to long and use it in further calculations.

Please see the patch with JUnit test and fix for GregorianCalendar code attached



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message