{"record":{"id":"4e2447cba1edea68","repo":"JetBrains/intellij-community","slug":"2-choice-1-flag-1-flags-0-not-allowed-in","errorCode":null,"errorMessage":"{2, choice, 1#flag|1<flags} ''{0}'' not allowed in ''{1}''","messagePattern":"(.+?) ''(.+?)'' not allowed in ''(.+?)''","errorType":"exception","errorClass":"FormatDecode.IllegalFormatException","httpStatus":null,"severity":"error","filePath":"java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java","lineNumber":128,"sourceCode":"      result.append('0');\n    }\n    if ((flags & GROUP) != 0) {\n      result.append(',');\n    }\n    if ((flags & PARENTHESES) != 0) {\n      result.append('(');\n    }\n    if ((flags & PREVIOUS) != 0) {\n      result.append('<');\n    }\n    return result.toString();\n  }\n\n  private static void checkFlags(int value, int allowedFlags, String specifier) {\n    final int result = value & ~allowedFlags;\n    if (result != 0) {\n      final String flags = flagString(result);\n      throw new IllegalFormatException(\n        InspectionGadgetsBundle.message(\"format.string.error.flags.not.allowed\", flags, specifier, flags.length()));\n    }\n  }\n\n  public static Validator[] decodePrefix(String prefix, int argumentCount) {\n    return decode(prefix, argumentCount, true, false);\n  }\n\n  public static Validator @NotNull [] decode(String formatString, int argumentCount) {\n    return decode(formatString, argumentCount, false, false);\n  }\n\n  public static Validator @NotNull [] decodeNoVerify(String formatString, int argumentCount) {\n    return decode(formatString, argumentCount, false, true);\n  }\n\n  /**\n   * A single format specifier.","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L110-L146","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nString.format(\"%+n\")\n// after\nString.format(\"%n\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { FormatDecode.decode(fmt, argc); } catch (IllegalFormatException e) { /* report offending specifier and its disallowed flags */ }","preventionTips":["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"],"tags":["intellij","format-string","inspection","java","parsing"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}