-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
None
-
b28
-
generic
-
generic
The following program shows that Calendar.equals changes the observable state of the calendar. The output I got is:
Date with equals: Tue May 30 20:25:08 PDT 2000
Date without equals: Sun Apr 30 20:25:08 PDT 2000
Calling a.equals(b) should never, ever have any observable effect on a or b.
import java.util.Calendar;
public class CalEquals {
public static void main(String[] args) {
Calendar cal1 = makeCalendar();
Calendar cal2 = makeCalendar();
Calendar cal3 = makeCalendar();
cal1.equals(cal2);
cal1.set(Calendar.DAY_OF_MONTH, 30);
cal3.set(Calendar.DAY_OF_MONTH, 30);
System.out.println("Date with equals: " + cal1.getTime());
System.out.println("Date without equals: " + cal3.getTime());
}
private static Calendar makeCalendar() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.APRIL);
cal.set(Calendar.DAY_OF_MONTH, 31);
return cal;
}
}
The Date class has the same problem since JDK1.0.
###@###.### 2002-08-05
Date with equals: Tue May 30 20:25:08 PDT 2000
Date without equals: Sun Apr 30 20:25:08 PDT 2000
Calling a.equals(b) should never, ever have any observable effect on a or b.
import java.util.Calendar;
public class CalEquals {
public static void main(String[] args) {
Calendar cal1 = makeCalendar();
Calendar cal2 = makeCalendar();
Calendar cal3 = makeCalendar();
cal1.equals(cal2);
cal1.set(Calendar.DAY_OF_MONTH, 30);
cal3.set(Calendar.DAY_OF_MONTH, 30);
System.out.println("Date with equals: " + cal1.getTime());
System.out.println("Date without equals: " + cal3.getTime());
}
private static Calendar makeCalendar() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.APRIL);
cal.set(Calendar.DAY_OF_MONTH, 31);
return cal;
}
}
The Date class has the same problem since JDK1.0.
###@###.### 2002-08-05
- relates to
-
JDK-5008227 java.sql.Timestamp.after() is not returning correct result
-
- Resolved
-
-
JDK-6912866 (date) java.util.Date.before / after may be expensive
-
- Resolved
-
-
JDK-4722650 Calendar.equals can throw an exception in non-lenient
-
- Resolved
-
-
JDK-6501204 (cal) Performance degradation in Calendar since upgrading from jdk 1.4.2 to 1.5.09
-
- Closed
-
-
JDK-6609279 (cal) GregorianCalendar methods before/equals/after have poor performance with JDK 1.5
-
- Closed
-