{"record":{"id":"1e5b3133422149ea","repo":"material-components/material-components-android","slug":"only-gregorian-calendars-are-supported","errorCode":null,"errorMessage":"Only Gregorian calendars are supported.","messagePattern":"Only Gregorian calendars are supported\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/datepicker/Month.java","lineNumber":151,"sourceCode":"  @Override\n  public int compareTo(@NonNull Month other) {\n    return firstOfMonth.compareTo(other.firstOfMonth);\n  }\n\n  /**\n   * Returns the number of months from this Month to the provided Month.\n   *\n   * <p>0 when {@code this.compareTo(other)} is 0. Negative when {@code this.compareTo(other)} is\n   * negative.\n   *\n   * @throws IllegalArgumentException when {@link Calendar#getInstance()} is not an instance of\n   *     {@link GregorianCalendar}\n   */\n  int monthsUntil(@NonNull Month other) {\n    if (firstOfMonth instanceof GregorianCalendar) {\n      return (other.year - year) * 12 + (other.month - month);\n    } else {\n      throw new IllegalArgumentException(\"Only Gregorian calendars are supported.\");\n    }\n  }\n\n  long getStableId() {\n    return firstOfMonth.getTimeInMillis();\n  }\n\n  /**\n   * Gets a long for the specific day within the instance's month and year.\n   *\n   * <p>This method only guarantees validity with respect to {@link Calendar#isLenient()}.\n   *\n   * @param day The desired day within this month and year\n   * @return A long representing a time in milliseconds for the given day within the specified month\n   *     and year\n   */\n  long getDay(int day) {\n    Calendar dayCalendar = UtcDates.getDayCopy(firstOfMonth);","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/datepicker/Month.java#L133-L169","documentation":"Month.monthsUntil computes month distance arithmetically and only works when the underlying Calendar is a GregorianCalendar (the arithmetic year*12+month is Gregorian-specific). If firstOfMonth is any other Calendar implementation, it throws IllegalArgumentException stating only Gregorian calendars are supported.","triggerScenarios":"The device/emulator default Calendar.getInstance() returning a non-Gregorian calendar (e.g. an ICU/islamic calendar on certain locales or OEM builds, or a custom Calendar subclass injected into the locale); constructing Month objects from calendars obtained outside UtcDates.","commonSituations":"Devices or emulators with non-Gregorian calendar locales; forked/OEM system images; code that builds Month.create from a Calendar obtained with Calendar.getInstance(nonGregorianLocale). In stock Material, months are created via UtcDates (UTC/US locale), so users normally only see this via locale-dependent entry points.","solutions":["Switch the affected calendar usage to a Gregorian locale: Calendar.getInstance(TimeZone.UTC, Locale.US) — the same policy UtcDates uses.","Change the device/emulator calendar setting to Gregorian if it is set to another calendar system.","Update Material Components; verify you are not constructing Month from a custom Calendar subclass."],"exampleFix":"// before\nval cal = Calendar.getInstance(localeWithNonGregorianCalendar)\nval month = Month.create(cal) // monthsUntil() later throws\n\n// after\nval cal = Calendar.getInstance(TimeZone.getTimeZone(\"UTC\"), Locale.US)\nval month = Month.create(cal)","handlingStrategy":"fallback","validationCode":"fun isGregorian(calendar: Calendar): Boolean = calendar is GregorianCalendar\n\nval cal = Calendar.getInstance(TimeZone.getTimeZone(\"UTC\"), Locale.US) // guaranteed Gregorian\nval month = Month.create(cal)","typeGuard":"fun supportsMonthArithmetic(cal: Calendar): Boolean = cal is GregorianCalendar","tryCatchPattern":"try { month.monthsUntil(other) } catch (e: IllegalArgumentException) { fall back to computing month distance from raw year/month fields, which is calendar-system-specific }","preventionTips":["Create all picker-related Calendars with a fixed Gregorian locale (UTC + Locale.US), matching UtcDates.","Avoid ICU/custom Calendar implementations in code paths that feed Material date pickers.","On QA devices, check Settings > Calendar uses Gregorian for affected locales."],"tags":["android","material-components","datepicker","calendar","locale"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}