libgdx/libgdx · error · IllegalArgumentException

Missing argument index after a left curly brace

Error message

Missing argument index after a left curly brace

What it means

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.

Source

Thrown at backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/TextFormatter.java:69

		for (int i = 0; i < patternLength; ++i) {
			char ch = pattern.charAt(i);
			if (placeholder < 0) { // processing constant part
				if (ch == '{') {
					changed = true;
					if (i + 1 < patternLength && pattern.charAt(i + 1) == '{') {
						buffer.append(ch); // handle escaped '{'
						++i;
					} else {
						placeholder = 0; // switch to placeholder part
					}
				} else {
					buffer.append(ch);
				}
			} else { // processing placeholder part
				if (ch == '}') {
					if (placeholder >= args.length) throw new IllegalArgumentException("Argument index out of bounds: " + placeholder);
					if (pattern.charAt(i - 1) == '{')
						throw new IllegalArgumentException("Missing argument index after a left curly brace");
					if (args[placeholder] == null)
						buffer.append("null"); // append null argument
					else
						buffer.append(args[placeholder].toString()); // append actual argument
					placeholder = -1; // switch to constant part
				} else {
					if (ch < '0' || ch > '9')
						throw new IllegalArgumentException("Unexpected '" + ch + "' while parsing argument index");
					placeholder = placeholder * 10 + (ch - '0');
				}
			}
		}
		if (placeholder >= 0) throw new IllegalArgumentException("Unmatched braces in the pattern.");

		return changed ? buffer.toString() : pattern;
	}
}

View on GitHub (pinned to 97f4086187)

Solutions

  1. Put an explicit index in the braces: {0}, {1}, ...
  2. For a literal brace, use the escaped form '{{' / '}}' which TextFormatter handles in the constant part.
  3. Lint translation files for empty brace pairs before GWT compilation.

Example fix

// before
format("brace: {}", null); // throws

// after
format("brace: '{{'}}", null); // literal { via escape
Defensive patterns

Strategy: validation

Validate before calling

if (pattern.contains("{}"))
    throw new IllegalStateException("empty placeholder '{}' in pattern: " + pattern);

Try / catch

try { formatter.format(pattern, args); }
catch (IllegalArgumentException e) { log pattern; fall back to pattern with braces normalized }

Prevention

When it happens

Trigger: A pattern containing "{}" (empty placeholder), e.g. format("set {}", value); also "a {}b" where the intent was a literal brace.

Common situations: 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.

Related errors


AI-assisted analysis of libgdx/libgdx@97f4086187 (2026-08-14). Data as JSON: /api/errors/c47e69dc4ad45d38. Report an issue: GitHub.