JDK-6609391 : (cal) Calendar method after doesn't complain if you pass it a Date (or any other Object)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-07-29
  • Resolved: 2007-10-19
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.
19-10-2007