{"record":{"id":"af7784404112ab9a","repo":"apache/flink","slug":"could-not-parse-avro-schema-string","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-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSchemaConverter.java","lineNumber":125,"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 & 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":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSchemaConverter.java#L107-L143","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nString schema = readConfig(\"schema.avsc\"); // accidentally the PATH string\nTypeInformation<?> ti = AvroSchemaConverter.convertToTypeInfo(schema);\n\n// after\nString schema = new String(Files.readAllBytes(Path.of(\"schema.avsc\")), UTF_8);\nnew Schema.Parser().parse(schema); // fail fast with precise error\nTypeInformation<?> ti = AvroSchemaConverter.convertToTypeInfo(schema);","handlingStrategy":"validation","validationCode":"try {\n    new Schema.Parser().parse(avroSchemaString);\n} catch (SchemaParseException e) {\n    throw new IllegalArgumentException(\"Invalid Avro schema JSON: \" + e.getMessage(), e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return AvroSchemaConverter.convertToTypeInfo(avroSchemaString, legacy);\n} catch (IllegalArgumentException e) {\n    if (e.getCause() instanceof SchemaParseException) {\n        // config-level bug: surface schema error, do not retry\n        throw new ConfigurationException(\"Fix the .avsc: \" + e.getCause().getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["avro","flink","schema-parsing","json","configuration"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}