{"record":{"id":"3cc3443acb3a2b69","repo":"apache/beam","slug":"encoderecord-failed","errorCode":null,"errorMessage":"encodeRecord failed!","messagePattern":"encodeRecord failed!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java","lineNumber":99,"sourceCode":"                .mapToObj(idx -> autoCastField(schema.getField(idx), rawRecord.get(idx)))\n                .collect(toRow(schema)));\n      }\n      return rows;\n    } catch (IOException e) {\n      throw new IllegalArgumentException(\n          String.format(\"Could not parse CSV records from %s with format %s\", line, csvFormat), e);\n    }\n  }\n\n  public static String beamRow2CsvLine(Row row, CSVFormat csvFormat) {\n    StringWriter writer = new StringWriter();\n    try (CSVPrinter printer = csvFormat.print(writer)) {\n      for (int i = 0; i < row.getFieldCount(); i++) {\n        printer.print(row.getBaseValue(i, Object.class).toString());\n      }\n      printer.println();\n    } catch (IOException e) {\n      throw new IllegalArgumentException(\"encodeRecord failed!\", e);\n    }\n    return writer.toString();\n  }\n\n  /**\n   * Attempt to cast an object to a specified Schema.Field.Type.\n   *\n   * @throws IllegalArgumentException if the value cannot be cast to that type.\n   * @return The casted object in Schema.Field.Type.\n   */\n  public static Object autoCastField(Schema.Field field, @Nullable Object rawObj) {\n    // handle null\n    if (rawObj == null) {\n      if (!field.getType().getNullable()) {\n        throw new IllegalArgumentException(String.format(\"Field %s not nullable\", field.getName()));\n      }\n      return null;\n    }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java#L81-L117","documentation":"beamRow2CsvLine failed to serialize a Beam Row into a CSV line: while printing the row's fields with the given CSVFormat, an IOException escaped the CSVPrinter, and it is wrapped in an IllegalArgumentException. Typically caused by a field value incompatible with the CSVFormat (e.g. a delimiter/quoting problem or a null in a non-nullable position), not by the CSV library itself failing.","triggerScenarios":"Row field values whose toString/write path makes the CSVPrinter throw an IOException, or the underlying StringWriter failing while printing fields.","commonSituations":"Rows containing values incompatible with the configured CSVFormat (e.g. characters needing unavailable escaping setups); rare writer/IO failures during serialization.","solutions":["Check that all Row field values are non-null and serializable to strings","Review the CSVFormat settings for compatibility with field contents","Catch the IllegalArgumentException to identify the offending row and log it"],"exampleFix":"// before\nrow.getBaseValue(i, Object.class).toString() // value may be null -> NPE/IO issues\n// after\nObject v = row.getBaseValue(i, Object.class);\nprinter.print(v == null ? \"\" : v.toString());","handlingStrategy":"try-catch","validationCode":"for (int i = 0; i < row.getFieldCount(); i++) { if (row.getBaseValue(i, Object.class) == null) throw new IllegalStateException(\"null field at \" + i); }","typeGuard":null,"tryCatchPattern":"try { csv = BeamTableUtils.beamRow2CsvLine(row, format); } catch (IllegalArgumentException e) { log.error(\"row serialization failed\", e); }","preventionTips":["Ensure all Row fields are non-null before serialization","Verify value types are stringifiable","Test CSVFormat escaping against real data"],"tags":["csv","serialization"],"backgroundTag":"json-marshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}