{"record":{"id":"f08bb7c7898b86d9","repo":"apache/pulsar","slug":"the-input-schema-is-not-of-type-org-apache-avro-s","errorCode":null,"errorMessage":"The input schema is not of type 'org.apache.avro.Schema'.","messagePattern":"The input schema is not of type 'org\\.apache\\.avro\\.Schema'\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/NativeAvroBytesSchema.java","lineNumber":64,"sourceCode":"        this.nativeSchema = schema;\n        Map<String, String> properties = new HashMap<>();\n        properties.put(ALWAYS_ALLOW_NULL, \"true\");\n        properties.put(JSR310_CONVERSION_ENABLED, \"false\");\n        this.schemaInfo = SchemaInfo.builder()\n            .name(\"\")\n            .schema(schema.toString().getBytes(StandardCharsets.UTF_8))\n            .properties(properties)\n            .type(SchemaType.AVRO)\n            .build();\n    }\n\n    public NativeAvroBytesSchema(Object schema) {\n        this(validateSchema(schema));\n    }\n\n    private static org.apache.avro.Schema validateSchema (Object schema) {\n        if (!(schema instanceof org.apache.avro.Schema)) {\n            throw new IllegalArgumentException(\"The input schema is not of type 'org.apache.avro.Schema'.\");\n        }\n        return (org.apache.avro.Schema) schema;\n    }\n\n    @Override\n    public byte[] encode(byte[] message) {\n        return message;\n    }\n\n    /* decode should not be used because this is a Schema to be used on the Producer side */\n    @Override\n    public byte[] decode(byte[] bytes, byte[] schemaVersion) {\n        throw new UnsupportedOperationException();\n    }\n\n    @Override\n    public SchemaInfo getSchemaInfo() {\n        return schemaInfo;","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/NativeAvroBytesSchema.java#L46-L82","documentation":"NativeAvroBytesSchema's constructor validates that the object passed in is an org.apache.avro.Schema instance. If it is anything else (a String, a POJO, a Class, etc.) it throws IllegalArgumentException immediately at schema construction.","triggerScenarios":"new NativeAvroBytesSchema(someString) or passing a Pulsar SchemaInfo/other schema object instead of a real org.apache.avro.Schema (e.g. Schema.Parser().parse(...) result).","commonSituations":"Mixing up Avro schema JSON text with a parsed Schema object; passing a SchemaDefinition or generic Object from generic API; refactors that changed the schema variable's type.","solutions":["Parse the raw JSON into an Avro Schema first: new Schema.Parser().parse(schemaJson)","Ensure the variable's compile-time type is org.apache.avro.Schema","Use Schema.AVRO(SomePojo.class) if you want a POJO-driven schema instead of NativeAvroBytesSchema"],"exampleFix":"// before\nNativeAvroBytesSchema s = new NativeAvroBytesSchema(\"{\"type\":\"record\"...}\");\n// after\norg.apache.avro.Schema avro = new Schema.Parser().parse(\"{\"type\":\"record\"...}\");\nNativeAvroBytesSchema s = new NativeAvroBytesSchema(avro);","handlingStrategy":"type-guard","validationCode":"if (!(obj instanceof org.apache.avro.Schema)) { throw new IllegalArgumentException(\"must be an org.apache.avro.Schema\"); }","typeGuard":"boolean isAvroSchema(Object o) { return o instanceof org.apache.avro.Schema; }","tryCatchPattern":"try { new NativeAvroBytesSchema<>(obj); } catch (IllegalArgumentException e) { /* parse schema from JSON and retry */ }","preventionTips":["Parse schema strings with new Schema.Parser().parse(...) before constructing","Keep variables typed as org.apache.avro.Schema","Prefer Schema.AVRO(Pojo.class) unless you specifically need native bytes passthrough"],"tags":["avro","schema","illegal-argument"],"backgroundTag":"invalid-schema-argument","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}