{"record":{"id":"1508997d06df56b6","repo":"apache/iceberg","slug":"could-not-parse-avro-schema-string-150899","errorCode":null,"errorMessage":"Could not parse Avro schema string.","messagePattern":"Could not parse Avro schema string\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java","lineNumber":127,"sourceCode":"  }\n\n  /**\n   * Converts an Avro schema string into a nested row structure with deterministic field order and\n   * data types that are compatible with Flink's Table &amp; SQL API.\n   *\n   * @param avroSchemaString Avro schema definition string\n   * @param legacyTimestampMapping legacy mapping of timestamp types\n   * @return type information matching the schema\n   */\n  @SuppressWarnings(\"unchecked\")\n  public static <T> TypeInformation<T> convertToTypeInfo(\n      String avroSchemaString, boolean legacyTimestampMapping) {\n    Preconditions.checkNotNull(avroSchemaString, \"Avro schema must not be null.\");\n    final Schema schema;\n    try {\n      schema = new Schema.Parser().parse(avroSchemaString);\n    } catch (SchemaParseException e) {\n      throw new IllegalArgumentException(\"Could not parse Avro schema string.\", e);\n    }\n    return (TypeInformation<T>) convertToTypeInfo(schema, legacyTimestampMapping);\n  }\n\n  private static TypeInformation<?> convertToTypeInfo(\n      Schema schema, boolean legacyTimestampMapping) {\n    switch (schema.getType()) {\n      case RECORD:\n        final List<Schema.Field> fields = schema.getFields();\n\n        final TypeInformation<?>[] types = new TypeInformation<?>[fields.size()];\n        final String[] names = new String[fields.size()];\n        for (int i = 0; i < fields.size(); i++) {\n          final Schema.Field field = fields.get(i);\n          types[i] = convertToTypeInfo(field.schema(), legacyTimestampMapping);\n          names[i] = field.name();\n        }\n        return Types.ROW_NAMED(names, types);","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.2/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java#L109-L145","documentation":"AvroSchemaConverter.convertToTypeInfo parses an Avro schema given as a JSON string before converting it to Flink TypeInformation. If Schema.Parser().parse fails (malformed JSON, invalid Avro constructs), it throws IllegalArgumentException('Could not parse Avro schema string.') with the SchemaParseException as cause.","triggerScenarios":"Calling AvroSchemaConverter.convertToTypeInfo(avroSchemaString, legacyTimestampMapping) with a string that is not valid Avro schema JSON: syntax errors, unknown types, truncated output, or non-JSON content.","commonSituations":"Reading the schema from a file/registry and getting HTML or a connection-error page; string truncated by logging; escaping issues when the schema is embedded in config or code; single vs double quote mixups.","solutions":["Validate the string with a JSON linter / Schema.Parser before passing it in; inspect the cause SchemaParseException for the exact position.","Ensure the schema is read completely from its source (registry, file, resource) and not truncated.","Fix escaping when the schema is embedded in Java strings or YAML/properties config.","Generate the schema programmatically via AvroSchemaConverter.convertToSchema(LogicalType) instead of hand-writing JSON."],"exampleFix":"// before\nString schema = \"{\\\"type\\\":\\\"record\\\",\\\"name\\\":\\\"R\\\",\\\"fields\\\":[{\"name\":\"a\",\"type\":\"int\"}\"; // truncated\n// after\nString schema = \"{\\\"type\\\":\\\"record\\\",\\\"name\\\":\\\"R\\\",\\\"fields\\\":[{\\\"name\\\":\\\"a\\\",\\\"type\\\":\\\"int\\\"}]}\";","handlingStrategy":"validation","validationCode":"try {\n  new Schema.Parser().parse(avroSchemaString);\n} catch (SchemaParseException e) {\n  throw new IllegalArgumentException(\"Invalid Avro schema supplied to pipeline: \" + e.getMessage(), e);\n}","typeGuard":null,"tryCatchPattern":"try { ti = AvroSchemaConverter.convertToTypeInfo(schemaString, legacy); } catch (IllegalArgumentException e) { log.error(\"Schema parse failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); throw e; }","preventionTips":["Validate schema strings at config-load time, not at job runtime.","Check that the schema registry/file response is JSON (guard against error pages).","Log the schema string (or its hash) with the failure to spot truncation/escaping issues."],"tags":["flink","avro","schema","parse-error"],"backgroundTag":"json-parse-error","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}