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.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);


Output in RI: 

Output in Harmony:

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


View raw message