From commits-return-60843-apmail-harmony-commits-archive=harmony.apache.org@harmony.apache.org Thu Nov 05 16:15:55 2009 Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 12919 invoked from network); 5 Nov 2009 16:15:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Nov 2009 16:15:55 -0000 Received: (qmail 46077 invoked by uid 500); 5 Nov 2009 16:15:55 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 46016 invoked by uid 500); 5 Nov 2009 16:15:55 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 46005 invoked by uid 99); 5 Nov 2009 16:15:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2009 16:15:55 +0000 X-ASF-Spam-Status: No, hits=-10.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2009 16:15:52 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 58A2D234C045 for ; Thu, 5 Nov 2009 08:15:32 -0800 (PST) Message-ID: <1850019701.1257437732357.JavaMail.jira@brutus> Date: Thu, 5 Nov 2009 16:15:32 +0000 (UTC) From: "Oliver Deakin (JIRA)" To: commits@harmony.apache.org Subject: [jira] Created: (HARMONY-6370) [classlib][luni] GregorianCalendar edge-case can result in infinite loop MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [classlib][luni] GregorianCalendar edge-case can result in infinite loop ------------------------------------------------------------------------ Key: HARMONY-6370 URL: https://issues.apache.org/jira/browse/HARMONY-6370 Project: Harmony Issue Type: Bug Components: Classlib Reporter: Oliver Deakin Running the following test: import java.util.*; class Test { public static void main(String[] args) { System.out.println("Starting Test..."); GregorianCalendar gcalendar = new GregorianCalendar(); gcalendar.setGregorianChange(new Date(Long.MIN_VALUE)); gcalendar.setTimeInMillis(Long.MIN_VALUE); System.out.println("Test Complete"); } } never returns from the setTimeInMillis() call. Calling setGregorianChange() with Long.MIN_VALUE is perfectly reasonable - it means you want to use a purely Gregorian calendar and is mentioned in the spec. Calling setTimeInMillis() with any value from Long.MIN_VALUE to approximately Long.MIN_VALUE+189485000000000L will cause an infinite loop to occur, so it is quite a broad range of values, albeit values that may never be used as they are so far in the past. Debugging in the GregorianCalendar code, I have found that the setGregorianCalendar(Long.MIN_VALUE) sets the change year from Julian to Gregorian calendars to be -292269054. However, once this value is set, calling setTimeInMillis(Long.MIN_VALUE) actually tries to create a calendar with a year slightly lower than this boundary value (because of the Gregorian leap year adjustments)! The result is that we oscillate either side of the boundary value (-292269054) infinitely as we switch from calculating the date in Gregorian to Julian calendars and back. Although this is a corner case, the RI can complete this test successfully so I think it is worth logging. I'm not sure what the best fix is. The simplest fix would probably be to check in setGregorianChange() if the Date being passed in is the earliest date possible, and if so just fixup the Gregorian change year to be Integer.MIN_VALUE instead of using the year from the specified Date. This will ensure that all dates set with that calendar will be calculated entirely in the Gregorian calendar (as described in the spec) and with this change I can no longer recreate the infinite loop. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.