JetBrains/intellij-community · error · FormatDecode.IllegalFormatException
{2, choice, 1#flag|1<flags} ''{0}'' not allowed in ''{1}''
Error message
{2, choice, 1#flag|1<flags} ''{0}'' not allowed in ''{1}'' What it means
IllegalFormatException from FormatDecode.checkFlags during format-string validation (the 'Format String' language injection and format-string inspections). It fires when a specifier uses flags not permitted for its conversion — the value carries bits outside allowedFlags. Message pluralizes 'flag/flags' by count. This mirrors java.util.Formatter semantics but is raised statically by the inspection.
Source
Thrown at java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java:128
result.append('0');
}
if ((flags & GROUP) != 0) {
result.append(',');
}
if ((flags & PARENTHESES) != 0) {
result.append('(');
}
if ((flags & PREVIOUS) != 0) {
result.append('<');
}
return result.toString();
}
private static void checkFlags(int value, int allowedFlags, String specifier) {
final int result = value & ~allowedFlags;
if (result != 0) {
final String flags = flagString(result);
throw new IllegalFormatException(
InspectionGadgetsBundle.message("format.string.error.flags.not.allowed", flags, specifier, flags.length()));
}
}
public static Validator[] decodePrefix(String prefix, int argumentCount) {
return decode(prefix, argumentCount, true, false);
}
public static Validator @NotNull [] decode(String formatString, int argumentCount) {
return decode(formatString, argumentCount, false, false);
}
public static Validator @NotNull [] decodeNoVerify(String formatString, int argumentCount) {
return decode(formatString, argumentCount, false, true);
}
/**
* A single format specifier.View on GitHub (pinned to be881553f2)
Solutions
- Remove the disallowed flags named in the message from that specifier
- Check the conversion character's allowed flags against java.util.Formatter docs (e.g. %n and %% accept none/minimal)
- Test the string with String.format at runtime to confirm the JDK agrees
Example fix
// before
String.format("%+n")
// after
String.format("%n") Defensive patterns
Strategy: try-catch
Try / catch
try { FormatDecode.decode(fmt, argc); } catch (IllegalFormatException e) { /* report offending specifier and its disallowed flags */ } Prevention
- Check each conversion's allowed flag set against java.util.Formatter before composing strings
- Run format strings through String.format in unit tests to catch static and runtime disagreement
When it happens
Trigger: A format specifier like '%+n' (flags not allowed for %n conversion, allowedFlags=0), '%0s' (zero-pad not allowed for %s), or '%#,e'. checkFlags(value & ~allowedFlags != 0) trips during decode() of the format string.
Common situations: Copy-pasting printf format strings between conversions (e.g. C-style '%05s'); using '+' or ',' with %n or %% where java.util.Formatter forbids them; inspections flagging migrated logging code.
Related errors
- unexpected character ''{0}'' in ''{1}''
- duplicate flag ''{0}'' in ''{1}''
- width (''{0}'') not allowed in ''{1}''
- unnecessary argument position specifier ''{0}'' in ''{1}''
- previous flag ''<'' used but no previous format specifier fo
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/4e2447cba1edea68.
Report an issue: GitHub.