{"record":{"id":"3567462bf2750ac6","repo":"HMCL-dev/HMCL","slug":"illegal-pattern-unclosed","errorCode":null,"errorMessage":"Illegal pattern (Unclosed ): ","messagePattern":"Illegal pattern \\(Unclosed \\): ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeNewInstallTask.java","lineNumber":241,"sourceCode":"        this.installer = installer;\n        this.selfVersion = selfVersion;\n\n        setSignificance(TaskSignificance.MAJOR);\n    }\n\n    private static String replaceTokens(Map<String, String> tokens, String value) {\n        StringBuilder buf = new StringBuilder();\n        for (int x = 0; x < value.length(); x++) {\n            char c = value.charAt(x);\n            if (c == '\\\\') {\n                if (x == value.length() - 1)\n                    throw new IllegalArgumentException(\"Illegal pattern (Bad escape): \" + value);\n                buf.append(value.charAt(++x));\n            } else if (c == '{' || c == '\\'') {\n                StringBuilder key = new StringBuilder();\n                for (int y = x + 1; y <= value.length(); y++) {\n                    if (y == value.length())\n                        throw new IllegalArgumentException(\"Illegal pattern (Unclosed \" + c + \"): \" + value);\n                    char d = value.charAt(y);\n                    if (d == '\\\\') {\n                        if (y == value.length() - 1)\n                            throw new IllegalArgumentException(\"Illegal pattern (Bad escape): \" + value);\n                        key.append(value.charAt(++y));\n                    } else {\n                        if (c == '{' && d == '}') {\n                            x = y;\n                            break;\n                        }\n                        if (c == '\\'' && d == '\\'') {\n                            x = y;\n                            break;\n                        }\n                        key.append(d);\n                    }\n                }\n                if (c == '\\'') {","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeNewInstallTask.java#L223-L259","documentation":"replaceTokens treats '{' and '\\'' as openers of token references ({KEY}) or quoted literals ('...'). If the scan reaches the end of the string without finding the matching closer, it throws IllegalArgumentException(\"Illegal pattern (Unclosed <c>): <value>\"). The message text appears with a trailing space because the closer char is appended as 'Unclosed ' + c where c is '{' or '\\''.","triggerScenarios":"A data value or processor argument passed to parseLiteral (not fully wrapped in {..} or '..') contains a '{' or '\\'' with no matching '}' or '\\'' before end of string, e.g. value \"unclosed{KEY\".","commonSituations":"Corrupted forge installer downloads; hand-edited install_profile.json dropping a closing brace/quote; unexpected installer format from very new Forge versions; values where a lone quote is used as an apostrophe in prose.","solutions":["Re-download the Forge installer from official sources to rule out corruption","Open the installer jar, inspect install_profile.json data values named in the message, and add the missing closing brace/quote","Use a different Forge version known to install correctly","Update HMCL to the latest version for broader installer-format compatibility"],"exampleFix":"// before (data value)\n{\"SRC\": \"{MINECRAFT_LIBS}\"\n// after\n{\"SRC\": \"{MINECRAFT_LIBS}\"}","handlingStrategy":"validation","validationCode":"// verify balanced braces/quotes in installer profile values before running\nlong open = json.chars().filter(c -> c == '{').count();\nlong close = json.chars().filter(c -> c == '}').count();\nif (open != close) throw new IllegalStateException(\"unbalanced braces in install_profile.json\");","typeGuard":null,"tryCatchPattern":"try { installTask.execute(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Unclosed\")) { reDownloadInstaller(); } else throw e; }","preventionTips":["Use official download sources for forge installer jars","Do not modify installer contents manually","If installs keep failing, try a different Forge version","Update HMCL when new Forge releases ship format changes"],"tags":["java","illegalargument","forge-installer","string-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}