{"record":{"id":"d04b6a9d99cb0ad0","repo":"JetBrains/intellij-community","slug":"left-justify-flag-used-but-width-not-specifi","errorCode":null,"errorMessage":"left justify flag ''-'' used but width not specified in ''{0}''","messagePattern":"left justify flag ''-'' 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":371,"sourceCode":"          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);\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()) {","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L353-L389","documentation":"Thrown when a format specifier uses the left-justify flag '-' but specifies no field width. Left justification only has meaning relative to a width (pad the field on the right up to N characters), so java.util.Formatter rejects '-' without a width; FormatDecode encodes the same rule (LEFT_JUSTIFY set while the parsed width string is empty) for the InspectionGadgets format-string checks.","triggerScenarios":"A specifier like \"%-d\" or \"%-s\" — the '-' flag present, but no numeric width between the flags and the conversion character — in a format string decoded by FormatDecode.","commonSituations":"A width digit accidentally deleted during refactoring; dynamically assembled specifiers where the width component is conditionally empty; template strings copied with a truncated specifier.","solutions":["Add an explicit width, e.g. \"%-10s\", if you actually want left-justified padding.","Remove the '-' flag, e.g. \"%s\", if alignment does not matter.","If the width is computed at runtime, make sure the width segment is only omitted together with the '-' flag."],"exampleFix":"// before\nString s = String.format(\"%-s\", \"hi\");\n\n// after\nString s = String.format(\"%-10s\", \"hi\");","handlingStrategy":"validation","validationCode":"static void checkJustifyHasWidth(String fmt) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"%(-)?(\\d+)?[a-zA-Z]\").matcher(fmt);\n  while (m.find()) {\n    if (\"-\".equals(m.group(1)) && m.group(2) == null) throw new IllegalArgumentException(\"'-' without width: \" + m.group());\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat '-' and its width as one unit when editing or generating specifiers","Add a unit test that formats every template string with sample args"],"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"}