Skip to content

DateTimePicker locale not supported [1 day] #3309

Closed

Description

@balazspeterfi

Description

After upgrading from v14 to v23 we are seeing a strange error message, that doesn't even make much sense. We don't have any locale specified for the picker.
image

image

The component seems to be working though.

Expected outcome

no error

Minimal reproducible example

private val startTime = DateTimePicker()

Steps to reproduce

open a page with a DateTimePicker

Environment

Vaadin version(s): 23.0.11
Flow: 23.0.8
OS: Windows 10

Browsers

Chrome

Activity

  1. Artur- commented on Jun 9, 2022

    @Artur-
    Member

    I tried to reproduce by adding a DateTimePicker but there is no error about locale. Probably needs some other setup code, browser local setting or server locale setting.

    Is it possible that you see this error in V14 also but it gets hidden in the browser console? V23 will bring the errors to your attention but with V14 they can just go by unnoticed

  2. balazspeterfi commented on Jun 13, 2022

    @balazspeterfi
    Author

    It only happens on v23, not on v14. we tried on multiple workstations and are getting the same error. I'm not even sure where it is getting the en-US locale as ours is en-GB plus it displays the time 24-hours format which is not US.

  3. balazspeterfi commented on Jun 13, 2022

    @balazspeterfi
    Author

    Even without being able to reproduce it's clearly an incorrect message in many ways:

    1. it says it doesn't support en-US so it is falling back to the default en-US ???
    2. even though it is supposedly "falls back" to en-US it is clearly not displaying in that locale
    3. where is the en-US even coming from?
  4. web-padawan commented on Jun 14, 2022

    @web-padawan
    Member

    Here is the relevant code that is responsible for showing a warning:

    try {
    // Check whether the locale is supported by the browser or not
    TEST_PM_TIME.toLocaleTimeString(locale);
    } catch (e) {
    locale = 'en-US';
    // FIXME should do a callback for server to throw an exception ?
    throw new Error(
    'vaadin-time-picker: The locale ' +
    locale +
    ' is not supported, falling back to default locale setting(en-US).'
    );
    }

    Note, the same is also tested in the DatePicker so ideally both should either pass or fail 🤔

    try {
    // Check whether the locale is supported or not
    new Date().toLocaleDateString(locale);
    } catch (e) {
    locale = 'en-US';
    console.warn('The locale is not supported, using default locale setting(en-US).');
    }

  5. changed the title [-]DateTimePicker locale not supported[/-] [+]DateTimePicker locale not supported [1 day][/+] on Jun 14, 2022
  6. yuriy-fix commented on Jun 14, 2022

    @yuriy-fix
    Contributor

    Let's research for 1 day if the issue could be reproduced in local.

  7. web-padawan commented on Sep 25, 2026

    @web-padawan
    Member

    it says it doesn't support en-US so it is falling back to the default en-US ???

    This was fixed in #9873.

  8. web-padawan commented on Sep 25, 2026

    @web-padawan
    Member

    Warning

    Automated reproduction — produced by the Claude Code repro skill. Needs human verification.
    The steps, verdict, and root-cause pointer below were generated automatically and must be confirmed by a human before being treated as authoritative.

    • Verdict: reproduced
    • Hypothesis tested: The bug is that TimePicker sends an ill-formed BCP 47 tag to its connector. It is triggered by a Locale whose language or country is not a valid subtag, such as new Locale("en_GB"). It is observable as vaadin-time-picker: The locale <tag> is not supported. in the console and the dev-mode error dialog.
    • Regression?: unknown. The Java tag-building code is identical on 23.0 and main. V14 likely swallowed the same error silently, as a maintainer suggested in the thread.
    • Fixed by: partially by fix: name the unsupported locale in the time picker error #9873. It fixed the misleading message only: the old catch block overwrote locale with en-US before building the text. The error itself still fires.
    • Duplicate of: none found
    • Branch: repro/3309, pushed to vaadin/flow-components
    • Reproduced on: flow-components @ main (25.4-SNAPSHOT, 5c881d1)
    • Present on main?: yes (still broken)
    • Theme / Browser: Lumo / Chromium (Playwright)
    • Screenshot (static bug): Pickers with valid and ill-formed locales

    Observed behavior

    Each DateTimePicker below gets an explicit locale. The ill-formed ones throw from the time picker connector:

    Error: vaadin-time-picker: The locale en_gb is not supported.
    Error: vaadin-time-picker: The locale e is not supported.
    Error: vaadin-time-picker: The locale en-GB_X is not supported.
    Error: vaadin-time-picker: The locale en1 is not supported.
    
    Row Java Locale Tag sent Error Date shown Time shown
    default none (UI en_US) en-US no 2/1/2024 2:30 PM
    uk Locale.UK en-GB no 02/01/2024 14:30
    underscore new Locale("en_GB") en_gb yes 2/1/2024 14:30
    hyphen new Locale("en-GB") en-gb no n/a n/a
    iw new Locale("iw", "IL") he-IL no n/a n/a

    The failing picker keeps working. The time part uses the web component default 24-hour format, because setLocale throws before it assigns i18n. The date part falls back silently to the browser locale. This matches all three points of the reporter:

    The date picker logs no warning for the same locale. DatePicker sends Locale.toLanguageTag(), which returns und for ill-formed locales, and the browser accepts und.

    Valid but unknown tags such as zz-ZZ do not throw. Only syntactically ill-formed tags do.

    Expected behavior

    No error. The time picker should fall back to a default locale, as the TimePicker.setLocale javadoc promises, and like DatePicker already does.

    Steps to reproduce

    1. Create new DateTimePicker() or new TimePicker().
    2. Give it an ill-formed locale, for example picker.setLocale(new Locale("en_GB")).
    3. The same happens without an explicit locale, when the UI locale is ill-formed. It can come from I18NProvider.getProvidedLocales(), UI.setLocale, or the JVM default locale.
    4. Open the page. The dev-mode error dialog shows vaadin-time-picker: The locale en_gb is not supported.

    Reproduction

    How to run: start the server (mvn … jetty:run) and open the route below.

    • Route / page: http://localhost:8080/repro-3309
    • Scaffold: vaadin-date-time-picker-flow-parent/vaadin-date-time-picker-flow-integration-tests/src/main/java/com/vaadin/flow/component/datetimepicker/Repro3309View.java
    • Query switch: ?lang=<language>&country=<country> renders new Locale(lang, country) next to the default picker.
    DateTimePicker picker = new DateTimePicker();
    picker.setLocale(new Locale("en_GB")); // tag sent to the connector: "en_gb"
    add(picker);

    Root cause (suspected)

    TimePicker.executeLocaleUpdate builds the tag by joining getLanguage() and getCountry() with no validation. An ill-formed value such as en_gb reaches the connector unchanged:

    private void executeLocaleUpdate() {
    Locale appliedLocale = getLocale();
    // we could support script & variant, but that requires more work on
    // client side to detect the different
    // number characters for other scripts (current only Arabic there)
    StringBuilder bcp47LanguageTag = new StringBuilder(
    appliedLocale.getLanguage());
    if (!appliedLocale.getCountry().isEmpty()) {
    bcp47LanguageTag.append("-").append(appliedLocale.getCountry());
    }
    runBeforeClientResponse(ui -> getElement().callJsFunction(
    "$connector.setLocale", bcp47LanguageTag.toString()));
    }

    The connector then throws instead of falling back:

    setLocale(locale: string): void {
    try {
    // Check whether the locale is supported by the browser or not
    TEST_PM_TIME.toLocaleTimeString(locale);
    } catch (e) {
    // FIXME should do a callback for server to throw an exception ?
    throw new Error(`vaadin-time-picker: The locale ${locale} is not supported.`);
    }

    DatePicker already handles this case with toLanguageTag() and an lvariant check:

    // For ill-formed locales, Locale.toLanguageTag() will append subtag
    // "lvariant" to it, which will cause the client side
    // Date().toLocaleDateString()
    // fallback to the system default locale silently.
    // This has been caught by DatePickerValidationPage::invalidLocale test
    // when running on
    // Chrome(73+)/FireFox(66)/Edge(42.17134).
    Locale appliedLocale = getLocale();
    String languageTag;
    if (!appliedLocale.toLanguageTag().contains("lvariant")) {
    languageTag = appliedLocale.toLanguageTag();
    } else if (appliedLocale.getCountry().isEmpty()) {
    languageTag = appliedLocale.getLanguage();
    } else {
    languageTag = appliedLocale.getLanguage() + "-"
    + appliedLocale.getCountry();
    }

    The javadoc promises an en-US fallback that the code never does:

    * If for some reason the browser doesn't support the given locale, the
    * en-US locale is used.

    Notes

    • Flow sets the session locale only from I18NProvider.getProvidedLocales() or Locale.getDefault(), never from Accept-Language directly. Headers such as en-GB-oxendict, zh-Hant-TW, en_GB and es-419 all left the UI at en_US and caused no error. The ill-formed locale in the report most likely came from application code, for example Locale("en_GB") in Kotlin.
    • Possible fix: build the time picker tag like DatePicker does. The alternative is a real fallback in the connector catch block. fix: name the unsupported locale in the time picker error #9873 left that fallback out on purpose, as a behavior change.
    • No IT pom.xml edits were needed.
  9. vaadin-bot commented on Sep 29, 2026

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 25.4.0-alpha1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions