{"record":{"id":"4e37d8f042eb830f","repo":"apache/hadoop","slug":"data-was-too-long-to-write-expected-less-than-or","errorCode":null,"errorMessage":"data was too long to write!  Expected less than or equal to {} bytes, but got {} bytes.","messagePattern":"data was too long to write!  Expected less than or equal to (.+?) bytes, but got (.+?) bytes\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java","lineNumber":403,"sourceCode":"    in.readFully(bytes, 0, len);\n    length = len;\n    textLength = -1;\n  }\n\n  /**\n   * Serialize. Write this object to out length uses zero-compressed encoding.\n   *\n   * @see Writable#write(DataOutput)\n   */\n  @Override\n  public void write(DataOutput out) throws IOException {\n    WritableUtils.writeVInt(out, length);\n    out.write(bytes, 0, length);\n  }\n\n  public void write(DataOutput out, int maxLength) throws IOException {\n    if (length > maxLength) {\n      throw new IOException(\"data was too long to write!  Expected \" +\n          \"less than or equal to \" + maxLength + \" bytes, but got \" +\n          length + \" bytes.\");\n    }\n    WritableUtils.writeVInt(out, length);\n    out.write(bytes, 0, length);\n  }\n\n  /**\n   * Returns true iff <code>o</code> is a Text with the same length and same\n   * contents.\n   */\n  @Override\n  public boolean equals(Object o) {\n    if (o instanceof Text)\n      return super.equals(o);\n    return false;\n  }\n","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java#L385-L421","documentation":"Text.write(DataOutput, int maxLength) enforces a caller-supplied byte cap before serializing: if the Text's current byte length exceeds maxLength it throws IOException(\"data was too long to write! Expected less than or equal to M bytes, but got N bytes.\"). It lets fixed-boundary formats reject oversized fields deterministically instead of writing a record the reader will refuse.","triggerScenarios":"Writing a Text into a length-bounded slot (file-format field, fixed-size record area, protocol field with a documented maximum) where the value's UTF-8 byte length exceeds the cap; limits tuned in characters but enforced in bytes with multi-byte content.","commonSituations":"User-supplied strings (names, identifiers, attributes) exceeding format limits; limits documented in characters but enforced on UTF-8 bytes; writer and reader disagreeing on the cap.","solutions":["Check text.getLength() against the cap up front and truncate to valid UTF-8 boundaries or reject with an actionable error.","Raise the cap on both writer and reader if larger values are legitimate for the format.","Validate input strings at ingestion (before they reach serialization) against the same limit."],"exampleFix":"// before\ntext.write(out, MAX_FIELD_BYTES);        // throws when text is longer\n\n// after: enforce the policy before serializing\nif (text.getLength() > MAX_FIELD_BYTES) {\n  throw new IllegalArgumentException(\"value exceeds \" + MAX_FIELD_BYTES\n      + \" bytes: \" + text);\n}\ntext.write(out, MAX_FIELD_BYTES);","handlingStrategy":"validation","validationCode":"if (text.getLength() > maxLength) {\n  throw new IllegalArgumentException(\n      \"Text is \" + text.getLength() + \" bytes, limit \" + maxLength);\n}\ntext.write(out, maxLength);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check Text.getLength() against the cap before every bounded write","Validate user-supplied strings at ingestion against the same byte limit","Keep writer and reader caps in one shared constant"],"tags":["text","size-limit","serialization","writable","hadoop"],"backgroundTag":"payload-too-large","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}