{"record":{"id":"c47e69dc4ad45d38","repo":"libgdx/libgdx","slug":"missing-argument-index-after-a-left-curly-brace","errorCode":null,"errorMessage":"Missing argument index after a left curly brace","messagePattern":"Missing argument index after a left curly brace","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/TextFormatter.java","lineNumber":69,"sourceCode":"\t\tfor (int i = 0; i < patternLength; ++i) {\n\t\t\tchar ch = pattern.charAt(i);\n\t\t\tif (placeholder < 0) { // processing constant part\n\t\t\t\tif (ch == '{') {\n\t\t\t\t\tchanged = true;\n\t\t\t\t\tif (i + 1 < patternLength && pattern.charAt(i + 1) == '{') {\n\t\t\t\t\t\tbuffer.append(ch); // handle escaped '{'\n\t\t\t\t\t\t++i;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tplaceholder = 0; // switch to placeholder part\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbuffer.append(ch);\n\t\t\t\t}\n\t\t\t} else { // processing placeholder part\n\t\t\t\tif (ch == '}') {\n\t\t\t\t\tif (placeholder >= args.length) throw new IllegalArgumentException(\"Argument index out of bounds: \" + placeholder);\n\t\t\t\t\tif (pattern.charAt(i - 1) == '{')\n\t\t\t\t\t\tthrow new IllegalArgumentException(\"Missing argument index after a left curly brace\");\n\t\t\t\t\tif (args[placeholder] == null)\n\t\t\t\t\t\tbuffer.append(\"null\"); // append null argument\n\t\t\t\t\telse\n\t\t\t\t\t\tbuffer.append(args[placeholder].toString()); // append actual argument\n\t\t\t\t\tplaceholder = -1; // switch to constant part\n\t\t\t\t} else {\n\t\t\t\t\tif (ch < '0' || ch > '9')\n\t\t\t\t\t\tthrow new IllegalArgumentException(\"Unexpected '\" + ch + \"' while parsing argument index\");\n\t\t\t\t\tplaceholder = placeholder * 10 + (ch - '0');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (placeholder >= 0) throw new IllegalArgumentException(\"Unmatched braces in the pattern.\");\n\n\t\treturn changed ? buffer.toString() : pattern;\n\t}\n}\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/TextFormatter.java#L51-L87","documentation":"While parsing a placeholder, TextFormatter hit a '}' immediately after '{' (pattern.charAt(i-1) == '{'), i.e. an empty brace pair '{}'. Placeholders must contain at least one digit, so an index-less {} is rejected with IllegalArgumentException. Note that '{}' is legal in java.text.MessageFormat (it evaluates to a literal '{'), which is why code ported from desktop fails only on GWT.","triggerScenarios":"A pattern containing \"{}\" (empty placeholder), e.g. format(\"set {}\", value); also \"a {}b\" where the intent was a literal brace.","commonSituations":"Translations or UI strings written for desktop MessageFormat that use {} to emit a literal brace; hand-edited resource files where the index inside braces was accidentally deleted.","solutions":["Put an explicit index in the braces: {0}, {1}, ...","For a literal brace, use the escaped form '{{' / '}}' which TextFormatter handles in the constant part.","Lint translation files for empty brace pairs before GWT compilation."],"exampleFix":"// before\nformat(\"brace: {}\", null); // throws\n\n// after\nformat(\"brace: '{{'}}\", null); // literal { via escape","handlingStrategy":"validation","validationCode":"if (pattern.contains(\"{}\"))\n    throw new IllegalStateException(\"empty placeholder '{}' in pattern: \" + pattern);","typeGuard":null,"tryCatchPattern":"try { formatter.format(pattern, args); }\ncatch (IllegalArgumentException e) { log pattern; fall back to pattern with braces normalized }","preventionTips":["Always write an explicit index inside braces.","Use '{{' and '}}' escapes for literal braces, not empty pairs.","Remember '{}' is not valid in the GWT TextFormatter even though MessageFormat tolerates it."],"tags":["i18n","format-string","gwt","libgdx"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}