Skip to content

Issue regarding Calendar.getFirstDayOfWeek() after upgrading to Java 21+ #1146

Description

@alexwibowo

Hi.

Our production system is currently running on Java 11. We are looking at upgrading to Java 25. But we noticed an interesting issue today, in relation to session start up.

FYI, our session configuration is:
start time: Sunday, Australia/Victoria, 13:00
end time: Saturday, America/New York, 17:00

Our server is running in en_AU locale (I'm not 100% if this matters, but I suspect this has something to do with the issue). I also noticed that with Java 25, start of week for en_AU is Monday, where as with Java 11, start of week for en_AU is Sunday.

So going back to the problem, at 10:00 AM Australia Victoria time today, when I run my test, our session wouldn't start. Upon debugging, I found that with Java 25, the session interval was set to:
Sunday 22 February 2:00 UTC --> Saturday 21 February 22:00 UTC.
Where as with Java 11, the session interval would be:
Sunday 22 February 2:00 UTC --> Saturday 28 February 22:00 UTC

I suspect the underlying issue here is due to the behaviour of setting DAY_OF_WEEK as well as the 'start of week'. When current day is Monday, setting the date to Sunday would cause:

  1. With Java 17 and below: going backward (because it is still in the same week)
  2. With Java 21 and above: going forward (because week start with Monday).

I have created the following GitHub repo to demonstrate the issue: https://github.com/alexwibowo/quickfixjTest
There are two branches:

  1. main branch is using Java 8
  2. feature/JDK-25 is using Java 25.

In particular, this bit of code is where I think the problem is :

intervalEnd.add(Calendar.WEEK_OF_YEAR, -1);

(I'm not sure why intervalEnd is subtracted by 1 here)

In my repo above, I tried to fix it by adding another week:
https://github.com/alexwibowo/quickfixjTest/blob/128875e442668bd99014d0c93fb5cb7befa2630f/lib/src/test/java/org/example/LibraryTest.java#L116

 if (intervalEnd.getTimeInMillis() < intervalStart.getTimeInMillis()) {
            intervalEnd.add(Calendar.WEEK_OF_YEAR, 1);
}

although my test passes, it failed in the quickfixj test suite (SessionScheduleTest)

Activity

  1. added theissue type on Feb 23, 2026
  2. chrjohn commented on Feb 23, 2026

    @chrjohn
    Member

    Hi @alexwibowo , isn't this #574 ? Did you try with master branch?

  3. alexwibowo commented on Feb 23, 2026

    @alexwibowo
    ContributorAuthor

    Interesting. I'll give that a try. Coincidentally I've just created a PR:
    #1147

    But let me try to run my test again master (pretty sure I updated my branch with master)

  4. alexwibowo commented on Feb 23, 2026

    @alexwibowo
    ContributorAuthor

    I had a look at #574, but I think the change there is within the code block for 'non stopping session' ? My session is not a 'non stopping session', so I think there is still issue ?

  5. chrjohn commented on Feb 23, 2026

    @chrjohn
    Member

    I had a look at #574, but I think the change there is within the code block for 'non stopping session' ? My session is not a 'non stopping session', so I think there is still issue ?

    The change cannot be in the "non stop session" block because such a session is not scheduled.

    Edit: are you sure you tested master? There are currently only SNAPSHOT builds of master, i.e. version 3.0.0.

  6. chrjohn commented on Feb 23, 2026

    @chrjohn
    Member

    Did you find anything regarding this in the JDK release notes? I would expect notes on such a change. I found a related issue but that was for JDK 9.

  7. alexwibowo commented on Feb 24, 2026

    @alexwibowo
    ContributorAuthor

    I had a look at #574, but I think the change there is within the code block for 'non stopping session' ? My session is not a 'non stopping session', so I think there is still issue ?

    The change cannot be in the "non stop session" block because such a session is not scheduled.

    Edit: are you sure you tested master? There are currently only SNAPSHOT builds of master, i.e. version 3.0.0.

    Apology for the confusion, Chris. What I meant was, in PR #574, the change was within the 'isWeekdaySession'. i.e. this code block:

     if (isWeekdaySession) {
                while (intervalStart.getTimeInMillis() > t.getTimeInMillis() ||
                        !validDayOfWeek(intervalStart)) {
                    intervalStart.add(Calendar.DAY_OF_WEEK, -1);
                    intervalEnd.add(Calendar.DAY_OF_WEEK, -1);
                }
    
               // this was the change.
                while (intervalEnd.getTimeInMillis() <= intervalStart.getTimeInMillis()) {
                    intervalEnd.add(Calendar.DAY_OF_WEEK, 1);
                }
    
            }
    
    

    In my case, my session is not a weekday session. So the execution will go to the 'else' block. So I still run into issue, even with the latest master.

    To answer your question regarding change in JDK release note - I had to do a bit of research on what caused this. But basically, I believe the issue stems out from the use of 'Calendar#set(DAY_OF_WEEK)'. i.e. the following call within 'DefaultSessionSchedule'.:

      intervalStart.set(Calendar.DAY_OF_WEEK, startTime.getDay());
    

    Our 'start time' is SUNDAY. Now here is the interesting part. I looked at what could cause the issue - and if we look at the implementation, there is a bit of code that relies on the 'getFirstDayOfWeek'. Essentially, it boils down to this class:

    sun.util.resources.cldr.CalendarData
    

    If you have a look at this class, there is a constant that follows the 'CLDR' standard. Java 11 (our old JVM) uses CLDR 33. Java 25 (our new JVM) uses CLDR 46.
    Running this code in Java 11 vs Java 25 will give different result for my locale (en_AU):

      System.out.println(WeekFields.of(Locale.of("en", "AU")).getFirstDayOfWeek());
    

    For Java 11, you will get Sunday, and for Java 25, you will get Monday.
    This is because in CLDR 40, they have made the change the start day of week for AU from Sunday to Monday. See: https://cldr.unicode.org/downloads/cldr-40

    "The default first day of the week is now Monday for Australia, and the default day period preferences for times have changed for CN (to “HH”) and TW (to “hb”, i.e. 12-hour with day periods instead of AM/PM)."

    So what does this mean? When I ran my code in Australia time, Monday morning (23 Feb 2026, 10 AM), the code above will try to obtain the start interval, by setting the 'day of week' to Sunday.

    • In Java 11, because a week starts with Sunday, when calling 'set day to sunday', I will get back Sunday 22 Feb 2026 10 AM
    • In Java 25, because a week now starts with Monday, when calling 'set day to sunday', I will get back Sunday 1 March 2026 10 AM.

    From there on , the calculation for the interval is wrong.

    Apology for the lengthy response - but I hope that's clear now. Did you get a chance to look at my PR? I have included a unit test, whereby I change the locale to en_AU. If you run that test in Java 11 (without the code change), that test will fail.

  8. chrjohn commented on Feb 25, 2026

    @chrjohn
    Member

    @alexwibowo thanks for the detailed explanation. Please check my comments on your PR.

  9. changed the title [-]Potential issue after upgrading to Java 21+[/-] [+]Issue regarding `Calendar.getFirstDayOfWeek()` after upgrading to Java 21+[/+] on Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions