{"record":{"id":"431b4f690521ec78","repo":"HMCL-dev/HMCL","slug":"theme-contrast-value-must-be-between-1-and-1","errorCode":null,"errorMessage":"Theme contrast value must be between -1 and 1: ","messagePattern":"Theme contrast value must be between -1 and 1: ","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeAppearance.java","lineNumber":354,"sourceCode":"\n    /// Reads an optional string field.\n    private static @Nullable String readString(JsonObject object, String field) {\n        JsonElement element = object.get(field);\n        if (element == null) {\n            return null;\n        }\n        if (!(element instanceof JsonPrimitive primitive) || !primitive.isString()) {\n            throw new JsonParseException(\"Theme field must be a string: \" + field);\n        }\n        return primitive.getAsString();\n    }\n\n    /// Returns a validated contrast value.\n    private static Contrast readContrastValue(double value) {\n        try {\n            return Contrast.of(value);\n        } catch (IllegalArgumentException e) {\n            throw new JsonParseException(\"Theme contrast value must be between -1 and 1: \" + value, e);\n        }\n    }\n\n    /// Adds a canonical contrast value to a JSON object.\n    private static void addContrast(JsonObject object, Contrast contrast) {\n        if (contrast.equals(Contrast.LOW)) {\n            object.addProperty(FIELD_CONTRAST, \"low\");\n        } else if (contrast.equals(Contrast.DEFAULT)) {\n            object.addProperty(FIELD_CONTRAST, \"standard\");\n        } else if (contrast.equals(Contrast.MEDIUM)) {\n            object.addProperty(FIELD_CONTRAST, \"medium\");\n        } else if (contrast.equals(Contrast.HIGH)) {\n            object.addProperty(FIELD_CONTRAST, \"high\");\n        } else {\n            object.addProperty(FIELD_CONTRAST, contrast.getValue());\n        }\n    }\n","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeAppearance.java#L336-L372","documentation":"Thrown by readContrastValue() (invoked from readContrast) when the theme's contrast setting parses to a numeric value outside the accepted [-1, 1] range. Contrast adjusts text/background emphasis, so values beyond this range would produce invalid rendering results. The input at fault is the theme manifest's contrast field value.","triggerScenarios":"Thrown at HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeAppearance.java:354 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the theme's contrast value to a number within -1 to 1, or use a named level (low/standard/medium/high).","Clamp parsed contrast values to [-1, 1] before passing them to Contrast resolution.","Remove the contrast field to use the default."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}