{"record":{"id":"4a7e7bf652f32efb","repo":"Bigkoo/Android-PickerView","slug":"illegal-lunar-date-must-be-like-that-year-190","errorCode":null,"errorMessage":"Illegal lunar date, must be like that:\n\tyear : 1900~2099\n\tmonth : 1~12\n\tday : 1~30","messagePattern":"Illegal lunar date, must be like that:\n\tyear : 1900~2099\n\tmonth : 1~12\n\tday : 1~30","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pickerview/src/main/java/com/bigkoo/pickerview/utils/LunarCalendar.java","lineNumber":143,"sourceCode":"\r\n    /**\r\n     * 将农历日期转换为公历日期\r\n     *\r\n     * @param year        农历年份\r\n     * @param month       农历月\r\n     * @param monthDay    农历日\r\n     * @param isLeapMonth 该月是否是闰月\r\n     * @return 返回农历日期对应的公历日期，year0, month1, day2.\r\n     */\r\n    public static final int[] lunarToSolar(int year, int month, int monthDay,\r\n                                           boolean isLeapMonth) {\r\n        int dayOffset;\r\n        int leapMonth;\r\n        int i;\r\n\r\n        if (year < MIN_YEAR || year > MAX_YEAR || month < 1 || month > 12\r\n                || monthDay < 1 || monthDay > 30) {\r\n            throw new IllegalArgumentException(\r\n                    \"Illegal lunar date, must be like that:\\n\\t\" +\r\n                            \"year : 1900~2099\\n\\t\" +\r\n                            \"month : 1~12\\n\\t\" +\r\n                            \"day : 1~30\");\r\n        }\r\n\r\n        dayOffset = (LUNAR_INFO[year - MIN_YEAR] & 0x001F) - 1;\r\n\r\n        if (((LUNAR_INFO[year - MIN_YEAR] & 0x0060) >> 5) == 2)\r\n            dayOffset += 31;\r\n\r\n        for (i = 1; i < month; i++) {\r\n            if ((LUNAR_INFO[year - MIN_YEAR] & (0x80000 >> (i - 1))) == 0)\r\n                dayOffset += 29;\r\n            else\r\n                dayOffset += 30;\r\n        }\r\n\r","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/Bigkoo/Android-PickerView/blob/e200d8c063aa2568d728854c048340ad2e4e0c0b/pickerview/src/main/java/com/bigkoo/pickerview/utils/LunarCalendar.java#L125-L161","documentation":"This IllegalArgumentException is thrown by LunarCalendar.lunarToSolar when converting a lunar date to a solar date with inputs outside the supported table range. The library's lunar calendar data only covers lunar years 1900-2099, months 1-12, and days 1-30, so any out-of-range value makes the conversion mathematically undefined for this library.","triggerScenarios":"Calling lunarToSolar(year, month, monthDay, isLeapMonth) with year < 1900 or > 2099, month outside 1-12, or day outside 1-30, e.g. passing a Calendar-derived solar year like 2026 into the lunar conversion, or an uninitialized/defaulted day of 0.","commonSituations":"Feeding Gregorian (solar) dates into the lunar API by mistake; computing a lunar date for a date outside the picker's supported century (e.g. 2100 default range edges); uninitialized int fields defaulting to 0; custom TimePicker configurations that mix solar and lunar mode.","solutions":["Validate the lunar year is within 1900-2099, month 1-12, day 1-30 before calling lunarToSolar","Ensure you are passing lunar-calendar values, not solar Calendar values, to lunarToSolar","Wrap the call in try-catch and fall back to a default in-range date or solar mode","Clamp/normalize out-of-range day values (e.g. day 0 -> 1, day 31 -> 30) if approximate results are acceptable"],"exampleFix":"// before\nCalendar solar = LunarCalendar.lunarToSolar(2100, 12, 30, false); // throws\n// after\nif (lunarYear >= 1900 && lunarYear <= 2099 && lunarMonth >= 1 && lunarMonth <= 12 && lunarDay >= 1 && lunarDay <= 30) {\n    Calendar solar = LunarCalendar.lunarToSolar(lunarYear, lunarMonth, lunarDay, isLeapMonth);\n} else {\n    Calendar solar = Calendar.getInstance(); // fallback\n}","handlingStrategy":"validation","validationCode":"static boolean isValidLunarDate(int year, int month, int day) {\n    return year >= 1900 && year <= 2099 && month >= 1 && month <= 12 && day >= 1 && day <= 30;\n}","typeGuard":null,"tryCatchPattern":"try {\n    Calendar solar = LunarCalendar.lunarToSolar(y, m, d, isLeap);\n} catch (IllegalArgumentException e) {\n    Calendar solar = Calendar.getInstance(); // safe fallback\n}","preventionTips":["Validate lunar year/month/day against 1900-2099 / 1-12 / 1-30 before converting","Do not pass solar Calendar values to lunar APIs","Clamp day values to 1-30 before conversion"],"tags":["android","lunar-calendar","date-conversion","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"e200d8c063aa2568d728854c048340ad2e4e0c0b","analyzedAt":"2026-09-07T23:07:09.243Z","contentChangedAt":"2026-09-07T23:07:09.243Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}