{"record":{"id":"df47fc8ff2e767f1","repo":"JetBrains/intellij-community","slug":"duplicate-flag-0-in-1","errorCode":null,"errorMessage":"duplicate flag ''{0}'' in ''{1}''","messagePattern":"duplicate flag ''(.+?)'' in ''(.+?)''","errorType":"exception","errorClass":"FormatDecode.IllegalFormatException","httpStatus":null,"severity":"error","filePath":"java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java","lineNumber":256,"sourceCode":"        isAllVerifier = true;\n      }\n      final String specifier = matcher.group();\n      final String posSpec = matcher.group(\"posSpec\");\n      final String flags = matcher.group(\"flags\");\n      final String width = matcher.group(\"width\");\n      final String precision = matcher.group(\"precision\");\n      final String dateSpec = matcher.group(\"dateSpec\");\n      final @NonNls String conversion = matcher.group(\"conversion\");\n\n      int flagBits = 0;\n      for (int j = 0; j < flags.length(); j++) {\n        final char flag = flags.charAt(j);\n        final int bit = flag(flag);\n        if (bit == -1) {\n          throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.unexpected.flag\", flag, specifier));\n        }\n        if ((flagBits | bit) == flagBits) {\n          throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.duplicate.flag\", flag, specifier));\n        }\n        flagBits |= bit;\n      }\n\n      // check this first because it should not affect \"implicit\"\n      if (\"n\".equals(conversion)) {\n        // no flags allowed\n        checkFlags(flagBits, 0, specifier);\n        if (!StringUtil.isEmpty(width)) {\n          throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.width.not.allowed\", width, specifier));\n        }\n        checkNoPrecision(precision, specifier);\n        continue;\n      }\n      else if (\"%\".equals(conversion)) { // literal '%'\n        checkFlags(flagBits, LEFT_JUSTIFY, specifier);\n        checkNoPrecision(precision, specifier);\n        continue;","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L238-L274","documentation":"IllegalFormatException from FormatDecode when the same flag appears twice in one specifier — detected by (flagBits | bit) == flagBits, i.e. the bit was already set. java.util.Formatter likewise rejects duplicate flags ('Duplicate format flag %s in format string'). The inspection reports it statically at the flagged specifier.","triggerScenarios":"Specifiers like '%--5s', '%00d', '%,,f'; decode() iterates the flag characters and re-setting an already-set bit throws.","commonSituations":"Concatenating flag strings programmatically so a flag is appended twice; copy-paste edits duplicating a character; regex-built formats in logging wrappers.","solutions":["Deduplicate flags in the specifier (keep one occurrence)","If building format strings dynamically, track applied flags in a Set before appending"],"exampleFix":"// before\nString.format(\"%--5s\", \"x\")\n// after\nString.format(\"%-5s\", \"x\")","handlingStrategy":"validation","validationCode":"static boolean noDuplicateFlags(String flags) {\n  return flags.chars().distinct().count() == flags.length();\n}","typeGuard":null,"tryCatchPattern":"try { FormatDecode.decode(fmt, argc); } catch (IllegalFormatException e) { /* report duplicated flag character */ }","preventionTips":["When concatenating flag fragments, accumulate them in a Set<Character> before building the specifier"],"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"}