Bug 9854 - GregorianCalendar does not validate months correctly
Summary: GregorianCalendar does not validate months correctly
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-26 02:46 UTC by jjc
Modified: 2005-03-23 21:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-05-21 02:28:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jjc 2003-02-26 02:46:00 UTC
GregorianCalendar fails to check months for validity as illustrated by the following example. (It also appears not to check days of the month.)

import java.util.GregorianCalendar;

class DateTest {
    static public void main(String[] args) {
	GregorianCalendar cal = new GregorianCalendar();
	cal.setLenient(false);
	cal.set(2000, -1, 20, 5, 5, 5);
	try {
	    cal.getTime();
	    System.err.println("incorrectly allowed");
	}
	catch (IllegalArgumentException e) {
	    System.err.println("correctly detected as illegal");
	}
    }
}

Release:
3.3 20030217
Comment 1 Andrew Pinski 2003-05-25 20:43:23 UTC
confirmed on mainline (20030525).
Comment 2 Michael Koch 2003-09-29 10:34:46 UTC
The testcase fails with JDK 1.4.2 too. I really wonder about that. 
Comment 3 Andrew Pinski 2004-05-21 02:28:48 UTC
But:
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

Rejects it (correctly detected as illegal) so ...
Comment 4 GCC Commits 2005-03-23 21:26:13 UTC
Subject: Bug 9854

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2005-03-23 21:26:00

Modified files:
	libjava        : ChangeLog 
	libjava/java/text: SimpleDateFormat.java 
	libjava/java/util: Calendar.java GregorianCalendar.java 

Log message:
	2005-03-23  Sven de Marothy  <sven@physto.se>
	
	PR libgcj/2641, PR libgcj/9854, PR libgcj/14892, PR libgcj/18083,
	PR libgcj/11085:
	* java/util/Calendar.java
	(set): Use starting day of week when one is needed if none is given.
	* java/text/SimpleDateFormat.java
	(parse): Handle 1-12 and 1-24 timestamps correctly.
	* java/util/GregorianCalendar.java
	(computeTime, computeFields): HOUR should be in 0-11 format.
	(nonLeniencyCheck): Adjust leniency checking to that fact.
	(getLinearDay): Should be private.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3431&r2=1.3432
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/text/SimpleDateFormat.java.diff?cvsroot=gcc&r1=1.32&r2=1.33
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/Calendar.java.diff?cvsroot=gcc&r1=1.27&r2=1.28
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/GregorianCalendar.java.diff?cvsroot=gcc&r1=1.26&r2=1.27

Comment 5 GCC Commits 2005-03-23 21:36:39 UTC
Subject: Bug 9854

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tromey@gcc.gnu.org	2005-03-23 21:36:25

Modified files:
	libjava        : ChangeLog 
	libjava/java/util: Calendar.java GregorianCalendar.java 
	libjava/java/text: SimpleDateFormat.java 

Log message:
	2005-03-23  Sven de Marothy  <sven@physto.se>
	
	PR libgcj/2641, PR libgcj/9854, PR libgcj/14892, PR libgcj/18083,
	PR libgcj/11085:
	* java/util/Calendar.java
	(set): Use starting day of week when one is needed if none is given.
	* java/text/SimpleDateFormat.java
	(parse): Handle 1-12 and 1-24 timestamps correctly.
	* java/util/GregorianCalendar.java
	(computeTime, computeFields): HOUR should be in 0-11 format.
	(nonLeniencyCheck): Adjust leniency checking to that fact.
	(getLinearDay): Should be private.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.22&r2=1.3391.2.23
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/Calendar.java.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.27&r2=1.27.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/GregorianCalendar.java.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.26&r2=1.26.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/text/SimpleDateFormat.java.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.32&r2=1.32.2.1

Comment 6 Tom Tromey 2005-03-23 21:39:19 UTC
Fix checked in.