{"record":{"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/310ac341f2f92a454b229bf21f70d2d18b2b6db7/gson/src/main/java/com/google/gson/FormattingStyle.java#L56-L92","documentation":"Thrown by FormattingStyle when the indent string contains anything other than spaces and tabs (validated by the regex [ \\t]*). Invoked via withIndent(...); an illegal indent rejects the style. This guarantees indentation can never inject arbitrary content into the JSON output.","triggerScenarios":"Calling withIndent(\"\\t \"); is fine, but withIndent(\"--\") or withIndent(\"\\u00a0\") (non-breaking space) throws; building indent from user-supplied config with stray characters; accidental inclusion of a newline in the indent.","commonSituations":"Config-driven indent strings pulled from YAML/properties with unexpected characters; copy-paste introducing unicode whitespace; trying to use a multi-character decorator as indent.","solutions":["Use only ASCII space (0x20) and tab (0x09) in the indent, e.g. withIndent(\"  \") or withIndent(\"\\t\").","Validate/sanitize the config value to spaces and tabs before constructing the FormattingStyle.","If a richer separator is needed, apply it as a post-processing step on the serialized output."],"exampleFix":"// before\nstyle.withIndent(\"\\u00a0\\u00a0\"); // non-breaking space -> throws\n\n// after\nstyle.withIndent(\"  \");","handlingStrategy":"validation","validationCode":"// Validate indent before constructing the style\nstatic String safeIndent(String s) {\n  if (s == null || !s.matches(\"[ \\\\t]*\")) {\n    throw new IllegalArgumentException(\"indent may only contain spaces and tabs\");\n  }\n  return s;\n}\nstyle.withIndent(safeIndent(configured));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use ASCII space/tab only.","Strip non-breaking spaces from config values.","Test FormattingStyle construction with the configured values."],"tags":["formatting-style","pretty-printing","configuration","validation"],"backgroundTag":null,"analyzedSha":"310ac341f2f92a454b229bf21f70d2d18b2b6db7","analyzedAt":"2026-08-10T02:58:47.455Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}