{"record":{"id":"cc90be89bbae3699","repo":"apache/iceberg","slug":"could-not-parse-avro-schema-string-cc90be","errorCode":null,"errorMessage":"Could not parse Avro schema string.","messagePattern":"Could not parse Avro schema string\\.","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/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.1/flink/src/main/java/org/apache/iceberg/flink/formats/avro/typeutils/AvroSchemaConverter.java#L109-L145","documentation":"AvroSchemaConverter.convertToTypeInfo wraps Avro SchemaParseException in an IllegalArgumentException when the supplied Avro schema string cannot be parsed. The original parse error is preserved as the cause.","triggerScenarios":"Calling AvroSchemaConverter.convertToTypeInfo(schemaString, ...) with malformed JSON, invalid Avro grammar, unknown type names, or unresolvable references in the schema string.","commonSituations":"Hand-edited schema strings with typos; schema loaded from a truncated file or environment variable; embedded quotes/newlines mangled when passing schemas through config.","solutions":["Validate the schema string with a standalone Avro parser (new Schema.Parser().parse(s)) to see the detailed error","Fix JSON syntax/typos in the schema string; ensure it is the schema, not the container file","Load the schema from a reliable source (file/classpath resource) rather than copy-paste","Check unresolved type references and namespaces in the schema"],"exampleFix":"// before: missing closing brace\nString s = \"{\\\"type\\\":\\\"record\\\",\\\"name\\\":\\\"R\\\",\\\"fields\\\":[{\\\"name\\\":\\\"a\\\",\\\"type\\\":\\\"int\\\"}\";\n// after\nString s = \"{\\\"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 IllegalStateException(\"Invalid Avro schema string: \" + e.getMessage(), e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  TypeInformation<?> ti = AvroSchemaConverter.convertToTypeInfo(schemaString, false);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().equals(\"Could not parse Avro schema string.\")) {\n    // log e.getCause() for the exact parse error and fix the schema\n  } else { throw e; }\n}","preventionTips":["Pre-validate schema strings with Schema.Parser before passing them in","Store schemas as classpath/file resources, not inline config strings","Check for truncation when schemas travel through env vars or UI inputs","Keep schemas under version control"],"tags":["flink","avro","schema","parse"],"backgroundTag":"schema-validation-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}