-
Bug
-
Resolution: Not an Issue
-
P4
-
8u111
-
generic
-
generic
FULL PRODUCT VERSION :
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
ubuntu 16.04 LTS 64-bit
A DESCRIPTION OF THE PROBLEM :
If you set DAY_OF_MONTH and DAY_OF_WEEK without reading the value of DAY_OF_MONTH between these two calls, changing the DAY_OF_WEEK doesn't recognize that DAY_OF_MONTH has been changed and will use the DAY_OF_WEEK from the previous data.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, Calendar.JANUARY);
c.set(Calendar.DAY_OF_MONTH, 25);
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH));
c.set(Calendar.DAY_OF_MONTH, 25);
System.out.println(c.get(Calendar.DAY_OF_MONTH));
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
20
25
20
ACTUAL -
6
25
20
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Calendar;
public class CalendarBug {
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, Calendar.JANUARY);
c.set(Calendar.DAY_OF_MONTH, 25);
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH)); // 6 -- should be 20 like below
c.set(Calendar.DAY_OF_MONTH, 25);
System.out.println(c.get(Calendar.DAY_OF_MONTH)); // 25
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH)); // 20 -- same as above, but c.get(Calendar.DAY_OF_MONTH) has been called between the two changes
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
just call calendar.get(Calendar.DAY_OF_MONTH) before setting DAY_OF_WEEK
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
ubuntu 16.04 LTS 64-bit
A DESCRIPTION OF THE PROBLEM :
If you set DAY_OF_MONTH and DAY_OF_WEEK without reading the value of DAY_OF_MONTH between these two calls, changing the DAY_OF_WEEK doesn't recognize that DAY_OF_MONTH has been changed and will use the DAY_OF_WEEK from the previous data.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, Calendar.JANUARY);
c.set(Calendar.DAY_OF_MONTH, 25);
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH));
c.set(Calendar.DAY_OF_MONTH, 25);
System.out.println(c.get(Calendar.DAY_OF_MONTH));
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
20
25
20
ACTUAL -
6
25
20
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Calendar;
public class CalendarBug {
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, Calendar.JANUARY);
c.set(Calendar.DAY_OF_MONTH, 25);
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH)); // 6 -- should be 20 like below
c.set(Calendar.DAY_OF_MONTH, 25);
System.out.println(c.get(Calendar.DAY_OF_MONTH)); // 25
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(c.get(Calendar.DAY_OF_MONTH)); // 20 -- same as above, but c.get(Calendar.DAY_OF_MONTH) has been called between the two changes
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
just call calendar.get(Calendar.DAY_OF_MONTH) before setting DAY_OF_WEEK