{"record":{"id":"5b98e008b378b40f","repo":"JetBrains/intellij-community","slug":"zero-padding-flag-0-used-but-width-not-specifi","errorCode":null,"errorMessage":"zero padding flag ''0'' used but width not specified in ''{0}''","messagePattern":"zero padding flag ''0'' used but width not specified in ''(.+?)''","errorType":"exception","errorClass":"FormatDecode.IllegalFormatException","httpStatus":null,"severity":"error","filePath":"java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java","lineNumber":374,"sourceCode":"        }\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);\n      if (!isPrefix) {\n        checkText(endString);\n      }\n      else {\n        //only case, when fsPattern doesn't find a specifier, is when there is no any conversion.\n        //add \"s\" as a random reasonable conversion\n        String suggestedString = endString + \"s\";\n        Matcher endMatcher = fsPattern.matcher(suggestedString);\n        if (!endMatcher.find() || endMatcher.end() != suggestedString.length()) {\n          checkText(endString);\n        }\n      }","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L356-L392","documentation":"Thrown when a specifier uses the zero-padding flag '0' but specifies no field width. Zero padding means 'pad with zeros up to width N'; without a width there is nothing to pad, so java.util.Formatter rejects it. FormatDecode applies the identical rule (ZERO_PAD set while width is empty) when validating format strings for the IG inspections.","triggerScenarios":"A specifier such as \"%0d\" or \"%05.1f\"-style strings where the width got dropped, leaving '0' with no following width digits (e.g. \"%0f\"), decoded by FormatDecode.","commonSituations":"Deleting the width while editing a format string; building specifiers from flag and width variables where the width is empty; misreading '0' as part of the width rather than as a flag.","solutions":["Add a width after the flags: \"%05d\" zero-pads an integer to 5 digits.","If you only wanted to print the number unchanged, drop the '0' flag entirely: \"%d\".","When constructing specifiers programmatically, emit the '0' flag only when a width is also emitted."],"exampleFix":"// before\nString s = String.format(\"%0d\", 42);\n\n// after\nString s = String.format(\"%05d\", 42);","handlingStrategy":"validation","validationCode":"static void checkZeroPadHasWidth(String fmt) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"%(0)(\\d+)?[a-zA-Z]\").matcher(fmt);\n  while (m.find()) {\n    if (m.group(2) == null) throw new IllegalArgumentException(\"'0' without width: \" + m.group());\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember '0' is a flag, not the first digit of the width","Lint generated format strings in CI with a small regex harness"],"tags":["format-string","java","static-analysis","validation"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}