apache/flink · error · IllegalArgumentException
Could not parse Avro schema string.
Error message
Could not parse Avro schema string.
What it means
AvroSchemaConverter.convertToTypeInfo(String, boolean) parses the supplied Avro schema string with Avro's Schema.Parser; SchemaParseException is wrapped in IllegalArgumentException('Could not parse Avro schema string.'). The string is not valid Avro schema JSON — syntax error, illegal type name, duplicate field, or malformed JSON.
Source
Thrown at flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSchemaConverter.java:125
}
/**
* Converts an Avro schema string into a nested row structure with deterministic field order and
* data types that are compatible with Flink's Table & SQL API.
*
* @param avroSchemaString Avro schema definition string
* @param legacyTimestampMapping legacy mapping of timestamp types
* @return type information matching the schema
*/
@SuppressWarnings("unchecked")
public static <T> TypeInformation<T> convertToTypeInfo(
String avroSchemaString, boolean legacyTimestampMapping) {
Preconditions.checkNotNull(avroSchemaString, "Avro schema must not be null.");
final Schema schema;
try {
schema = new Schema.Parser().parse(avroSchemaString);
} catch (SchemaParseException e) {
throw new IllegalArgumentException("Could not parse Avro schema string.", e);
}
return (TypeInformation<T>) convertToTypeInfo(schema, legacyTimestampMapping);
}
private static TypeInformation<?> convertToTypeInfo(
Schema schema, boolean legacyTimestampMapping) {
switch (schema.getType()) {
case RECORD:
final List<Schema.Field> fields = schema.getFields();
final TypeInformation<?>[] types = new TypeInformation<?>[fields.size()];
final String[] names = new String[fields.size()];
for (int i = 0; i < fields.size(); i++) {
final Schema.Field field = fields.get(i);
types[i] = convertToTypeInfo(field.schema(), legacyTimestampMapping);
names[i] = field.name();
}
return Types.ROW_NAMED(names, types);View on GitHub (pinned to 2f3c205e92)
Solutions
- Feed the exact schema content and validate it first: new Schema.Parser().parse(schemaString) in a unit test or at config load time to get the precise Avro error position.
- Check for mangling: escaped quotes, HTML entities, truncation, or a path being read as literal text.
- Use Avro tooling (avro-tools tojson/fromjson or an .avsc linter) to canonicalize the schema.
Example fix
// before
String schema = readConfig("schema.avsc"); // accidentally the PATH string
TypeInformation<?> ti = AvroSchemaConverter.convertToTypeInfo(schema);
// after
String schema = new String(Files.readAllBytes(Path.of("schema.avsc")), UTF_8);
new Schema.Parser().parse(schema); // fail fast with precise error
TypeInformation<?> ti = AvroSchemaConverter.convertToTypeInfo(schema); Defensive patterns
Strategy: validation
Validate before calling
try {
new Schema.Parser().parse(avroSchemaString);
} catch (SchemaParseException e) {
throw new IllegalArgumentException("Invalid Avro schema JSON: " + e.getMessage(), e);
} Try / catch
try {
return AvroSchemaConverter.convertToTypeInfo(avroSchemaString, legacy);
} catch (IllegalArgumentException e) {
if (e.getCause() instanceof SchemaParseException) {
// config-level bug: surface schema error, do not retry
throw new ConfigurationException("Fix the .avsc: " + e.getCause().getMessage(), e);
}
throw e;
} Prevention
- Parse every schema string with Avro's parser at config load, not at job runtime.
- Store schemas as files, not inline strings, to avoid quoting/escaping corruption.
- Run avro-tools or a JSON schema lint in CI.
When it happens
Trigger: Calling convertToTypeInfo with a malformed .avsc string: trailing commas, wrong JSON, invalid names (fields starting with digits), duplicate record names, or accidentally passing a file path / classpath reference instead of the schema content.
Common situations: Loading schema strings from config/REST/CLI where quoting or escaping mangles JSON; passing a URL/path instead of content; hand-edited schemas with typos; copy-paste truncation.
Related errors
- Schema must be set when using Generic Record
- Unsupported type: {}
- Number of input splits has to be at least 1.
- Output file path may not be null.
- Delimiter must not be null
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/af7784404112ab9a.
Report an issue: GitHub.