{"id":"fe2c9ac68fb3d416","repo":"google/gson","slug":"unknown-dateformat-style-timestyle","errorCode":null,"errorMessage":"Unknown DateFormat style: {timeStyle}","messagePattern":"Unknown DateFormat style: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/internal/PreJava9DateFormatProvider.java","lineNumber":61,"sourceCode":"        return \"MMMM d, yyyy\";\n      case DateFormat.FULL:\n        return \"EEEE, MMMM d, yyyy\";\n      default:\n        throw new IllegalArgumentException(\"Unknown DateFormat style: \" + dateStyle);\n    }\n  }\n\n  private static String getTimePartOfDateTimePattern(int timeStyle) {\n    switch (timeStyle) {\n      case DateFormat.SHORT:\n        return \"h:mm a\";\n      case DateFormat.MEDIUM:\n        return \"h:mm:ss a\";\n      case DateFormat.FULL:\n      case DateFormat.LONG:\n        return \"h:mm:ss a z\";\n      default:\n        throw new IllegalArgumentException(\"Unknown DateFormat style: \" + timeStyle);\n    }\n  }\n}\n","sourceCodeStart":43,"sourceCodeEnd":65,"githubUrl":"https://github.com/google/gson/blob/8b8628c65699bc4421696183c62ae0c1b9b281dc/gson/src/main/java/com/google/gson/internal/PreJava9DateFormatProvider.java#L43-L65","documentation":"Thrown by PreJava9DateFormatProvider.getTimePartOfDateTimePattern as IllegalArgumentException when the timeStyle argument is not one of DateFormat.SHORT, MEDIUM, LONG, or FULL. Note LONG and FULL map to the same time pattern ('h:mm:ss a z'); any other int (including DEFAULT or out-of-range values) hits the default branch and is rejected.","triggerScenarios":"Calling getUsDateTimeFormat(dateStyle, timeStyle) with an invalid timeStyle; or internal Gson usage when constructing a default time format whose style constant is outside the four supported values.","commonSituations":"Passing DateFormat.DEFAULT or a raw int for time style; forwarding an unchecked style from configuration/interop code; assuming all DateFormat.* constants are supported.","solutions":["Restrict timeStyle to DateFormat.SHORT, MEDIUM, LONG, or FULL; validate before calling.","For custom time formats, construct a SimpleDateFormat with an explicit pattern.","Coerce DEFAULT to MEDIUM before invoking the provider."],"exampleFix":"// before\nDateFormat f = PreJava9DateFormatProvider.getUsDateTimeFormat(DateFormat.SHORT, 7); // throws\n\n// after: valid constant or explicit pattern\nDateFormat f = PreJava9DateFormatProvider.getUsDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);\n// or\nDateFormat f = new SimpleDateFormat(\"M/d/yy h:mm:ss a\", Locale.US);","handlingStrategy":"validation","validationCode":"static void checkTimeStyle(int style) {\n  if (style != DateFormat.SHORT && style != DateFormat.MEDIUM\n      && style != DateFormat.LONG && style != DateFormat.FULL) {\n    throw new IllegalArgumentException(\"Unsupported time style: \" + style);\n  }\n}","typeGuard":"static boolean isValidTimeStyle(int s) {\n  return s == DateFormat.SHORT || s == DateFormat.MEDIUM\n      || s == DateFormat.LONG || s == DateFormat.FULL;\n}","tryCatchPattern":"try {\n  PreJava9DateFormatProvider.getUsDateTimeFormat(dateStyle, timeStyle);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"timeStyle\")) {\n    timeStyle = DateFormat.MEDIUM;\n  } else throw e;\n}","preventionTips":["Restrict timeStyle to SHORT/MEDIUM/LONG/FULL.","Use an explicit SimpleDateFormat pattern for custom formats.","Coerce DEFAULT to MEDIUM before invoking the provider."],"tags":["gson","date","dateformat","illegalargumentexception","pre-java9"],"analyzedSha":"8b8628c65699bc4421696183c62ae0c1b9b281dc","analyzedAt":"2026-08-04T19:12:22.202Z","schemaVersion":2}