{"record":{"id":"aeac9c397e78abcb","repo":"JetBrains/intellij-community","slug":"illegal-flag-combination-0-and-1-in","errorCode":null,"errorMessage":"illegal flag combination ''{0}'' and ''{1}'' in ''{2}''","messagePattern":"illegal flag combination ''(.+?)'' and ''(.+?)'' in ''(.+?)''","errorType":"exception","errorClass":"FormatDecode.IllegalFormatException","httpStatus":null,"severity":"error","filePath":"java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java","lineNumber":362,"sourceCode":"          }\n          case 'e', 'E' -> { // floating point -> decimal number in computerized scientific notation\n            checkFlags(flagBits, ~GROUP, specifier);\n            allowed = new FloatValidator(specifier);\n          }\n          case 'g', 'G' -> { // scientific notation\n            checkFlags(flagBits, ~ALTERNATE, specifier);\n            allowed = new FloatValidator(specifier);\n          }\n          case 'f' -> // floating point -> decimal number\n            allowed = new FloatValidator(specifier);\n          default -> throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.unknown.conversion\", specifier));\n        }\n      }\n      if (precision != null && precision.length() < 2) {\n        throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.invalid.precision\", specifier));\n      }\n      if (isAllBitsSet(flagBits, LEADING_SPACE | PLUS)) {\n        throw new IllegalFormatException(\n          InspectionGadgetsBundle.message(\"format.string.error.illegal.flag.combination\", ' ', '+', specifier));\n      }\n      if (isAllBitsSet(flagBits, LEFT_JUSTIFY | ZERO_PAD)) {\n        throw new IllegalFormatException(\n          InspectionGadgetsBundle.message(\"format.string.error.illegal.flag.combination\", '-', '0', specifier));\n      }\n      if (StringUtil.isEmpty(width)) {\n        if (isAllBitsSet(flagBits, LEFT_JUSTIFY)) {\n          throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.left.justify.no.width\", specifier));\n        }\n        if (isAllBitsSet(flagBits, ZERO_PAD)) {\n          throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.zero.padding.no.width\", specifier));\n        }\n      }\n      storeValidator(allowed, pos, parameters, argumentCount);\n    }\n    if (i < formatString.length()) {\n      String endString = formatString.substring(i);","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L344-L380","documentation":"Thrown while decoding a java.util.Formatter-style format specifier, this IllegalFormatException reports that the flags ' ' (leading space) and '+' (plus) were used together in the same specifier. The rules mirror java.util.Formatter: ' ' and '+' are mutually exclusive because both control the sign of numeric output. In IntelliJ this decode logic powers the 'Format String' inspection family, so the exception surfaces as an inspection error on the offending String.format/String.printf argument.","triggerScenarios":"A format string containing a specifier like \"% +d\" or \"%+ f\" — i.e. both the space flag and the plus flag set on the same conversion — passed to String.format, printf, Formatter, or scanned by the IG format-string inspections via FormatDecode.","commonSituations":"Copy-pasted format strings from C/printf code that allowed '% +d'; hand-built specifiers where flags are appended programmatically and both flags end up set; running the 'Format String' inspection on legacy code.","solutions":["Remove one of the two flags: use \"%+d\" when you always want a sign, or \"% d\" when you want a space only for non-negative values.","If the specifier is built dynamically, audit the flag-accumulation code so mutually exclusive flags cannot both be set.","Re-run the inspection after the edit to confirm the warning clears."],"exampleFix":"// before\nString s = String.format(\"% +d\", 42); // ' ' and '+' together\n\n// after\nString s = String.format(\"%+d\", 42); // always show sign","handlingStrategy":"validation","validationCode":"// Reject ' ' + '+' in one specifier before formatting\nstatic String checkFlags(String fmt) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"%[-#+ 0,(]*\").matcher(fmt);\n  while (m.find()) {\n    String f = m.group();\n    if (f.contains(\" \") && f.contains(\"+\")) throw new IllegalArgumentException(\"' ' and '+' combined in \" + f);\n  }\n  return fmt;\n}","typeGuard":null,"tryCatchPattern":"try { String r = String.format(fmt, arg); } catch (IllegalFormatException e) { /* fall back to plain toString */ }","preventionTips":["Keep format string literals in constants and review flags once","Use the IDE 'Format String' inspection to catch flag conflicts statically","When building specifiers dynamically, validate with a single regex over the flag region"],"tags":["format-string","java","static-analysis","validation"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}