{"record":{"id":"f1f939a0b66c7d43","repo":"JetBrains/intellij-community","slug":"unexpected-character-0-in-1","errorCode":null,"errorMessage":"unexpected character ''{0}'' in ''{1}''","messagePattern":"unexpected character ''(.+?)'' in ''(.+?)''","errorType":"exception","errorClass":"FormatDecode.IllegalFormatException","httpStatus":null,"severity":"error","filePath":"java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java","lineNumber":253,"sourceCode":"      //theoretically, it could be a correct specifier, divided into several parts, for example: \"%1$t\" + \"Y\"\n      //it is better to add ALL_VERIFIER\n      if (noVerify || isPrefix && i == formatString.length()) {\n        isAllVerifier = true;\n      }\n      final String specifier = matcher.group();\n      final String posSpec = matcher.group(\"posSpec\");\n      final String flags = matcher.group(\"flags\");\n      final String width = matcher.group(\"width\");\n      final String precision = matcher.group(\"precision\");\n      final String dateSpec = matcher.group(\"dateSpec\");\n      final @NonNls String conversion = matcher.group(\"conversion\");\n\n      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 '%'","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-analysis-impl/src/com/siyeh/ig/format/FormatDecode.java#L235-L271","documentation":"IllegalFormatException from FormatDecode when a flag character inside a format specifier is not recognized at all — flag(flag) returned -1. Recognized flags are '-','#','+',' ','0',',' and '('; anything else in the flags region (which the regex may capture loosely, e.g. letters) triggers this. It is the 'unexpected character' variant, distinct from disallowed-but-known flags.","triggerScenarios":"A specifier whose flags area contains an unrecognized character, e.g. '%=5d' or '%l5d'; typically from typos or regex-loose matching of malformed specifiers during decode().","commonSituations":"Typos in format strings; converting from other format dialects (MessageFormat, python) leaving stray characters; smart-quote corruption when pasting.","solutions":["Correct the specifier to use only legal flags: '- # + 0 , ('","Escape literal percent as '%%' instead of a malformed specifier","Re-run the inspection after fixing to catch follow-on errors"],"exampleFix":"// before\nString.format(\"%=5d\", 42)\n// after\nString.format(\"%5d\", 42)","handlingStrategy":"validation","validationCode":"private static final Set<Character> KNOWN_FLAGS = Set.of('-', '#', '+', ' ', '0', ',', '(');\nstatic boolean flagsRecognized(String flags) {\n  return flags.chars().allMatch(c -> KNOWN_FLAGS.contains((char) c));\n}","typeGuard":null,"tryCatchPattern":"try { FormatDecode.decode(fmt, argc); } catch (IllegalFormatException e) { /* point at the specifier containing the unknown character */ }","preventionTips":["Use only '- # + 0 , (' as flags","Escape literal text and '%' correctly ('%%') instead of leaving stray characters"],"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"}