{"record":{"id":"b45fce8893ca0c42","repo":"HMCL-dev/HMCL","slug":"invalid-instant","errorCode":null,"errorMessage":"Invalid instant: ","messagePattern":"Invalid instant: ","errorType":"exception","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/InstantTypeAdapter.java","lineNumber":111,"sourceCode":"\n    /// Parses an instant from one of the supported textual representations.\n    ///\n    /// @param string the text to parse\n    /// @return the parsed instant\n    /// @throws JsonParseException if `string` is not in a supported instant format\n    public static Instant deserializeToInstant(String string) {\n        try {\n            return ZonedDateTime.parse(string, EN_US_FORMAT).toInstant();\n        } catch (DateTimeParseException ex1) {\n            try {\n                ZonedDateTime zonedDateTime = ZonedDateTime.parse(string, ISO_DATE_TIME);\n                return zonedDateTime.toInstant();\n            } catch (DateTimeParseException e) {\n                try {\n                    LocalDateTime localDateTime = LocalDateTime.parse(string, ISO_LOCAL_DATE_TIME);\n                    return localDateTime.atZone(ZoneId.systemDefault()).toInstant();\n                } catch (DateTimeParseException e2) {\n                    throw new JsonParseException(\"Invalid instant: \" + string, e);\n                }\n            }\n        }\n    }\n\n    /// Formats an instant as an ISO offset date-time string in the given time zone.\n    ///\n    /// The output is truncated to whole seconds.\n    ///\n    /// @param instant the instant to format\n    /// @param zone    the time zone used to render the instant\n    /// @return the formatted instant\n    public static String serializeToString(Instant instant, ZoneId zone) {\n        return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.ofInstant(instant, zone).truncatedTo(ChronoUnit.SECONDS));\n    }\n}\n","sourceCodeStart":93,"sourceCodeEnd":128,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/InstantTypeAdapter.java#L93-L128","documentation":"deserializeToInstant tries several DateTimeFormatter patterns (ISO offset/zoned, ISO local date-time) and throws this JsonParseException when none of them can parse the string. The original DateTimeParseException is attached as the cause.","triggerScenarios":"Deserializing an Instant field whose string value is in an unrecognized format: epoch millis as string, \"dd/MM/yyyy HH:mm\", a locale-specific EN_US format produced by a different JDK, or a truncated date.","commonSituations":"Data written by older HMCL versions using the legacy US localized formatter, values saved with a different system default timezone/locale, or hand-edited config timestamps.","solutions":["Re-serialize the value in ISO-8601 format (Instant.toString() or DateTimeFormatter.ISO_OFFSET_DATE_TIME).","Parse the legacy format yourself with DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.US) and convert to Instant before passing it on.","Check the string for timezone information; ISO_LOCAL_DATE_TIME paths use ZoneId.systemDefault(), so supply an explicit zone when converting.","Confirm no whitespace or locale-specific month/day names are present in the stored value."],"exampleFix":"// before\n{\"timestamp\": \"07/03/24 9:06 AM\"} // legacy localized format\n// after\n{\"timestamp\": \"2024-07-03T09:06:00Z\"} // ISO-8601","handlingStrategy":"try-catch","validationCode":"try {\n    Instant.parse(value);\n    return true;\n} catch (DateTimeParseException e) {\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return gson.fromJson(json, Instant.class);\n} catch (JsonParseException e) {\n    // fall back to legacy localized format\n    Instant t = LocalDateTime.parse(raw, LEGACY_EN_US_FORMAT).atZone(ZoneId.systemDefault()).toInstant();\n}","preventionTips":["Store timestamps in ISO-8601 (Instant.toString()).","Never persist locale-dependent date formats.","Include timezone offsets in stored strings.","Migrate legacy EN_US formatted values once on config load."],"tags":["gson","date-parsing","iso8601"],"backgroundTag":"invalid-date-format","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}