{"record":{"id":"81612627f891ca6d","repo":"JetBrains/intellij-community","slug":"precision-0-not-allowed-in-1","errorCode":null,"errorMessage":"precision (''{0}'') not allowed in ''{1}''","messagePattern":"precision \\(''(.+?)''\\) 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":410,"sourceCode":"      }\n    }\n\n    return parameters.toArray(new Validator[0]);\n  }\n\n  private static DateTimeConversionType getDateTimeConversionType(char conversion) {\n    return switch (conversion) {\n      case 'H', 'I', 'k', 'l', 'M', 'S', 'L', 'N', 'p', 'R', 'T', 'r' -> DateTimeConversionType.TIME;\n      case 'z', 'Z' -> DateTimeConversionType.ZONE;\n      case 's', 'Q', 'c' -> DateTimeConversionType.ZONED_DATE_TIME;\n      case 'B', 'b', 'h', 'A', 'a', 'C', 'Y', 'y', 'j', 'm', 'd', 'e', 'D', 'F' -> DateTimeConversionType.DATE;\n      default -> DateTimeConversionType.UNKNOWN;\n    };\n  }\n\n  private static void checkNoPrecision(String precision, String specifier) {\n    if (!StringUtil.isEmpty(precision)) {\n      throw new IllegalFormatException(InspectionGadgetsBundle.message(\"format.string.error.precision.not.allowed\", precision, specifier));\n    }\n  }\n\n  private static boolean isAllBitsSet(int value, int mask) {\n    return (value & mask) == mask;\n  }\n\n  private static void checkText(String s) {\n    if (s.indexOf('%') != -1) {\n      throw new IllegalFormatException();\n    }\n  }\n\n  private static void storeValidator(Validator validator, int pos, ArrayList<Validator> parameters, int argumentCount) {\n    if (pos < parameters.size()) {\n      final Validator existing = parameters.get(pos);\n      if (existing == null) {\n        parameters.set(pos, validator);","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L392-L428","documentation":"checkNoPrecision throws when a '.'-based precision is supplied to a conversion that does not accept one. In java.util.Formatter, precision is meaningful only for string, character, and floating-point conversions; date/time conversions ('%tH', '%tY', ...) and others reject it. FormatDecode calls checkNoPrecision while building validators for such conversions, reproducing Formatter's rules inside the inspection.","triggerScenarios":"A format string like \"%.3tY\" or \"%.2c\"-style misuse — most commonly a precision applied to a date/time conversion (e.g. \"%.3TB\") — reaching getDateTimeConversionType/checkNoPrecision during decode.","commonSituations":"Copy-pasting a float specifier and changing only the conversion character to 't'; assuming precision truncates date output; the 'Format String' inspection flagging a calendar-formatting call.","solutions":["Remove the '.n' precision segment from the offending date/time or precision-less specifier (e.g. \"%.3tY\" -> \"%tY\").","If you need truncated date text, format the date fully and substring it afterwards.","For numeric conversions where precision is legal, keep it (e.g. \"%.3f\"); only the unsupported conversions reject it."],"exampleFix":"// before\nString y = String.format(\"%.3tY\", Calendar.getInstance());\n\n// after\nString y = String.format(\"%tY\", Calendar.getInstance());","handlingStrategy":"validation","validationCode":"static final java.util.Set<Character> PRECISION_OK = java.util.Set.of('s','S','f','e','E','g','G','a','A');\nstatic void checkPrecisionAllowed(String fmt) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"%[-#+ 0,(]*\\d*(?:\\.(\\d+))?([a-zA-Z])\").matcher(fmt);\n  while (m.find()) {\n    if (m.group(1) != null && !PRECISION_OK.contains(m.group(2).charAt(0)))\n      throw new IllegalArgumentException(\"precision not allowed for %\" + m.group(2));\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never carry '.n' over when changing a conversion char to 't' or an integer conversion","Truncate date text after formatting, not with precision"],"tags":["format-string","java","date","static-analysis","validation"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}