{"record":{"id":"2dc987f5de747423","repo":"material-components/material-components-android","slug":"firstdayofweek-is-not-valid","errorCode":null,"errorMessage":"firstDayOfWeek is not valid","messagePattern":"firstDayOfWeek is not valid","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/datepicker/CalendarConstraints.java","lineNumber":81,"sourceCode":"      @Nullable Month openAt,\n      int firstDayOfWeek) {\n    Objects.requireNonNull(start, \"start cannot be null\");\n    Objects.requireNonNull(end, \"end cannot be null\");\n    Objects.requireNonNull(validator, \"validator cannot be null\");\n    this.start = start;\n    this.end = end;\n    this.openAt = openAt;\n    this.firstDayOfWeek = firstDayOfWeek;\n    this.validator = validator;\n    if (openAt != null && start.compareTo(openAt) > 0) {\n      throw new IllegalArgumentException(\"start Month cannot be after current Month\");\n    }\n    if (openAt != null && openAt.compareTo(end) > 0) {\n      throw new IllegalArgumentException(\"current Month cannot be after end Month\");\n    }\n    if (firstDayOfWeek < 0\n        || firstDayOfWeek > UtcDates.getUtcCalendar().getMaximum(Calendar.DAY_OF_WEEK)) {\n      throw new IllegalArgumentException(\"firstDayOfWeek is not valid\");\n    }\n    monthSpan = start.monthsUntil(end) + 1;\n    yearSpan = end.year - start.year + 1;\n  }\n\n  boolean isWithinBounds(long date) {\n    return start.getDay(1) <= date && date <= end.getDay(end.daysInMonth);\n  }\n\n  /**\n   * Returns the {@link DateValidator} that determines whether a date can be clicked and selected.\n   */\n  public DateValidator getDateValidator() {\n    return validator;\n  }\n\n  /** Returns the earliest month allowed by this set of bounds. */\n  @NonNull","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/datepicker/CalendarConstraints.java#L63-L99","documentation":"CalendarConstraints requires firstDayOfWeek to be within 0..getMaximum(DAY_OF_WEEK) (typically 7, and 0 means 'use locale default'). Values outside that range throw IllegalArgumentException in the constructor, because the picker grids cannot be laid out with an invalid week-day index.","triggerScenarios":"Builder().setFirstDayOfWeek(v) with v < 0 or v > 7 (e.g. passing Calendar.DAY_OF_WEEK constants like 8+, or a config value parsed as 8+); forwarding an unvalidated server/local-storage setting into the builder.","commonSituations":"Remote-config-driven first-day-of-week (1=Mon ... 7=Sun schemes) mapped incorrectly onto the API's expected range; locale-aware code computing the value from Calendar.getFirstDayOfWeek but mixing in a default of -1 for 'unset'.","solutions":["Validate and clamp: use 0 for locale default, else ensure 1..7 before setFirstDayOfWeek.","Check the mapping of your configuration scheme (ISO-8601 1=Monday vs java.util.Calendar 1=Sunday) to the picker's expectation.","Default to not calling setFirstDayOfWeek at all when the value is unknown."],"exampleFix":"// before\nval constraints = CalendarConstraints.Builder()\n    .setFirstDayOfWeek(configStartOfWeek) // e.g. 8 from server config -> throws\n    .build()\n\n// after\nval fdow = configStartOfWeek.coerceIn(0, 7)\nval constraints = CalendarConstraints.Builder()\n    .setFirstDayOfWeek(fdow)\n    .build()","handlingStrategy":"validation","validationCode":"fun Int.toValidFirstDayOfWeek(): Int = coerceIn(0, 7) // 0 = locale default, 1..7 valid\n\nval constraints = CalendarConstraints.Builder()\n    .setFirstDayOfWeek(configFdow.toValidFirstDayOfWeek())\n    .build()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember 0 means locale default; 1..7 are the valid explicit values.","Validate any remotely configured first-day-of-week before use.","Write a unit test for the mapping between your config scheme and this API's range."],"tags":["android","material-components","datepicker","validation","calendar"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}