JDK-8359859 : Calendar.roll(DAY_OF_WEEK) incorrectly changes year across boundaries
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 8u431,24.0.1
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-06-17
  • Updated: 2025-06-17
Description
A DESCRIPTION OF THE PROBLEM :
GregorianCalendar.roll(Calendar.DAY_OF_WEEK, true) incorrectly modifies the year field when rolling from Saturday to Sunday across year boundaries, violating the documented behavior that roll() should not change larger fields.


---------- BEGIN SOURCE ----------
import java.util.Calendar;
import java.util.GregorianCalendar;

public class RollTest {
    public static void main(String args[]) {
        Calendar cal = new GregorianCalendar();
        cal.set(2020, Calendar.JANUARY, 4);
        System.out.println("Before roll: " + cal.getTime() + ", Year: " + cal.get(Calendar.YEAR));
        cal.roll(Calendar.DAY_OF_WEEK, 1);
        System.out.println("After roll: " + cal.getTime() + ", Year: " + cal.get(Calendar.YEAR));
    }
}

---------- END SOURCE ----------


Comments
Tested on Windows 11 Tested with JDK 24.0.2 JDK 21.0.26 JDK 8u431 All test results produced same output as reported in this bug. Before roll: Sat Jan 04 11:35:28 PST 2020, Year: 2020 After roll: Sun Dec 29 11:35:28 PST 2019, Year: 2019 Additional information: This report looks similar to below bugs. JDK-6902861 (cal) GregorianCalendar roll WEEK_OF_YEAR is broken for January 1 2010 This case reports the "roll" operation on DAY_OF_WEEK is incorrect.
17-06-2025

Impact -> M (Somewhere in-between the extremes) Likelihood -> L (Uncommon uses) Workaround -> H, no workaround Priority -> P4
17-06-2025