{"id":"e89ca2bd15fde35e","repo":"google/gson","slug":"only-combinations-of-spaces-and-tabs-are-allowed-i","errorCode":null,"errorMessage":"Only combinations of spaces and tabs are allowed in indent.","messagePattern":"Only combinations of spaces and tabs are allowed in indent\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/FormattingStyle.java","lineNumber":74,"sourceCode":"   * The default pretty printing formatting style:\n   *\n   * <ul>\n   *   <li>{@code \"\\n\"} as newline\n   *   <li>two spaces as indent\n   *   <li>a space between {@code ':'} and the subsequent value\n   * </ul>\n   */\n  public static final FormattingStyle PRETTY = new FormattingStyle(\"\\n\", \"  \", true);\n\n  private FormattingStyle(String newline, String indent, boolean spaceAfterSeparators) {\n    Objects.requireNonNull(newline, \"newline == null\");\n    Objects.requireNonNull(indent, \"indent == null\");\n    if (!newline.matches(\"[\\r\\n]*\")) {\n      throw new IllegalArgumentException(\n          \"Only combinations of \\\\n and \\\\r are allowed in newline.\");\n    }\n    if (!indent.matches(\"[ \\t]*\")) {\n      throw new IllegalArgumentException(\n          \"Only combinations of spaces and tabs are allowed in indent.\");\n    }\n    this.newline = newline;\n    this.indent = indent;\n    this.spaceAfterSeparators = spaceAfterSeparators;\n  }\n\n  /**\n   * Creates a {@link FormattingStyle} with the specified newline setting.\n   *\n   * <p>It can be used to accommodate certain OS convention, for example hardcode {@code \"\\n\"} for\n   * Linux and macOS, {@code \"\\r\\n\"} for Windows, or call {@link java.lang.System#lineSeparator()}\n   * to match the current OS.\n   *\n   * <p>Only combinations of {@code \\n} and {@code \\r} are allowed.\n   *\n   * @param newline the string value that will be used as newline.\n   * @return a newly created {@link FormattingStyle}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/google/gson/blob/8b8628c65699bc4421696183c62ae0c1b9b281dc/gson/src/main/java/com/google/gson/FormattingStyle.java#L56-L92","documentation":"Thrown by the FormattingStyle constructor (invoked via withIndent(...)) when the supplied indent string contains any character other than space (' ') and tab ('\\t'). The validator runs the regex [ \\t]*, so only combinations of spaces and tabs are allowed as indentation; any other character (a letter, a digit, a newline, a literal backslash) is rejected with IllegalArgumentException.","triggerScenarios":"Calling FormattingStyle.PRETTY.withIndent(\"    \") is fine, but withIndent(\"--\") or withIndent(\"\\t-\") or withIndent(\"\\\\t\") (literal backslash-t) throws; trying to use a visible indent marker for debugging; passing a newline-containing string; user-supplied indent config with stray characters.","commonSituations":"Confusing the escape \\t with the literal two-character string \"\\t\"; using visual debug markers as indent; copy-paste from config that double-escapes tabs; passing whitespace that is actually a non-breaking space (U+00A0), which is neither ' ' nor '\\t'.","solutions":["Pass only spaces and/or tabs: \"  \", \"\\t\", \"    \\t\", etc.","If indent comes from config, map symbolic names (\"tab\", \"2spaces\", \"4spaces\") to real characters.","Validate with input.matches(\"[ \\t]*\") before calling withIndent.","Watch for non-breaking spaces (U+00A0) copied from rich-text editors; replace with normal spaces."],"exampleFix":"// before: literal backslash-t or non-whitespace indent\nFormattingStyle s = FormattingStyle.PRETTY.withIndent(\"--\"); // throws\n\n// after: spaces and tabs only\nFormattingStyle s = FormattingStyle.PRETTY.withIndent(\"  \");","handlingStrategy":"validation","validationCode":"// Map symbolic indent names and validate before withIndent\nstatic String resolveIndent(String spec) {\n  if (spec == null) return \"\";\n  switch (spec) {\n    case \"tab\": return \"\\t\";\n    case \"2spaces\": return \"  \";\n    case \"4spaces\": return \"    \";\n    case \"\": return \"\";\n    default:\n      if (!spec.matches(\"[ \\\\t]*\")) throw new IllegalArgumentException(\"Invalid indent: \" + spec);\n      return spec;\n  }\n}\nFormattingStyle s = FormattingStyle.PRETTY.withIndent(resolveIndent(configValue));","typeGuard":"static boolean isValidIndent(String s) {\n  return s != null && s.matches(\"[ \\\\t]*\");\n}","tryCatchPattern":null,"preventionTips":["Use only spaces and tabs for indent.","Watch for non-breaking spaces (U+00A0) from rich-text editors; replace with normal spaces.","Map config symbols to characters at a single boundary.","Validate indent with a regex before constructing the FormattingStyle."],"tags":["formatting","indent","pretty-print","configuration","validation"],"analyzedSha":"8b8628c65699bc4421696183c62ae0c1b9b281dc","analyzedAt":"2026-08-04T19:12:22.202Z","schemaVersion":2}