{"record":{"id":"ccce5e6dec92fccf","repo":"JetBrains/intellij-community","slug":"width-0-not-allowed-in-1","errorCode":null,"errorMessage":"width (''{0}'') not allowed in ''{1}''","messagePattern":"width \\(''(.+?)''\\) 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":266,"sourceCode":"      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;\n      }\n\n      if (posSpec != null) {\n        if (isAllBitsSet(flagBits, PREVIOUS)) {\n          throw new IllegalFormatException(\n            InspectionGadgetsBundle.message(\"format.string.error.unnecessary.position.specifier\", posSpec, specifier));\n        }\n        final String num = posSpec.substring(0, posSpec.length() - 1);\n        pos = Integer.parseInt(num) - 1;\n        if (pos < 0) {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L248-L284","documentation":"IllegalFormatException from FormatDecode when the %n (line separator) conversion is given a width, e.g. '%10n'. %n takes no flags, width, or precision; the decoder first zeroes allowed flags then explicitly rejects a non-empty width before also rejecting precision. Matches java.util.Formatter's runtime behavior statically.","triggerScenarios":"A format string containing '%<width>n' such as '%5n' or '%-8n'; width group non-empty while conversion equals 'n'.","commonSituations":"Padding attempts on platform line separators; template generators inserting widths for every placeholder; misunderstanding %n as a generic newline placeholder with printf-style padding.","solutions":["Remove the width from the %n specifier; use plain '%n'","If you need padded output, use a literal newline via %s with a padded string or restructure the format"],"exampleFix":"// before\nString.format(\"column%8n\")\n// after\nString.format(\"column%n\")","handlingStrategy":"validation","validationCode":"static boolean widthAllowedFor(String conversion) {\n  return !\"n\".equals(conversion); // %n forbids flags, width, and precision\n}","typeGuard":null,"tryCatchPattern":"try { FormatDecode.decode(fmt, argc); } catch (IllegalFormatException e) { /* strip width from the %n specifier */ }","preventionTips":["Treat %n as a bare newline token: no flags, width, or precision","For padded newlines build them from %n and manual padding"],"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"}