United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6609391 : (cal) Calendar method after doesn't complain if you pass it a Date (or any other Object)

Details
Type:
Bug
Submit Date:
2007-09-26
Status:
Closed
Updated Date:
2010-07-29
Project Name:
JDK
Resolved Date:
2007-10-19
Component:
core-libs
OS:
linux
Sub-Component:
java.util:i18n
CPU:
x86
Priority:
P4
Resolution:
Won't Fix
Affected Versions:
5.0
Fixed Versions:

Related Reports

Sub Tasks

Description
FULL PRODUCT VERSION :
javaLinux1.5.0_05


ADDITIONAL OS VERSION INFORMATION :
2.6.16-1.2111_FC5

A DESCRIPTION OF THE PROBLEM :
When the "after" method in the Calendar class is passed a non-Calendar object (and more specifically a Date object), it does not throw an exception.  It should either handle the comparison with the Date properly, or throw an exception.

    public boolean after(Object when) {
	return when instanceof Calendar
	    && compareTo((Calendar)when) > 0;
    }

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
call "after" with a non-Calendar argument

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect to see an exception.
ACTUAL -
It returns false, when that may or may not be case.

REPRODUCIBILITY :
This bug can be reproduced always.

                                    

Comments
EVALUATION

The source code history shows that after() and before() were implemented in the current form in 1.1.6 as GregorianCalendar methods and were promoted to Calendar in 1.2. It's hard to change the implementation at this point. Please use compareTo(Calendar) added in 1.5.0.
                                     
2007-10-19



Hardware and Software, Engineered to Work Together