apache/pulsar · error · SchemaSerializationException

Can't get accurate schema information for ${topicName} using

Error message

Can't get accurate schema information for ${topicName} using KeyValueSchemaImpl because SchemaInfoProvider is not set yet

What it means

KeyValueSchemaImpl.fetchSchemaIfNeeded needs to look up the schema for the message's schema version, but no SchemaInfoProvider has been attached to this schema (usually set by the consumer/reader when connecting). Without a provider the client cannot resolve the versioned schema, so it throws SchemaSerializationException.

Source

Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaImpl.java:446

     * We cannot call this method in getSchemaInfo.
     * @see AutoConsumeSchema#fetchSchemaIfNeeded(SchemaVersion)
     */
    public void fetchSchemaIfNeeded(String topicName, SchemaVersion schemaVersion) throws SchemaSerializationException {
        if (schemaInfo != null) {
            if (keySchema instanceof AutoConsumeSchema) {
                ((AutoConsumeSchema) keySchema).fetchSchemaIfNeeded(schemaVersion);
            }
            if (valueSchema instanceof AutoConsumeSchema) {
                ((AutoConsumeSchema) valueSchema).fetchSchemaIfNeeded(schemaVersion);
            }
            return;
        }
        setSchemaInfoProviderOnSubschemas();
        if (schemaVersion == null) {
            schemaVersion = BytesSchemaVersion.of(new byte[0]);
        }
        if (schemaInfoProvider == null) {
            throw new SchemaSerializationException("Can't get accurate schema information for " + topicName + " "
                    + "using KeyValueSchemaImpl because SchemaInfoProvider is not set yet");
        } else {
            SchemaInfo schemaInfo;
            try {
                schemaInfo = schemaInfoProvider.getSchemaByVersion(schemaVersion.bytes()).get();
                if (schemaInfo == null) {
                    // schemaless topic
                    schemaInfo = BytesSchema.of().getSchemaInfo();
                }
                configureSchemaInfo(topicName, "topic", schemaInfo);
            } catch (InterruptedException | ExecutionException e) {
                if (e instanceof InterruptedException) {
                    Thread.currentThread().interrupt();
                }
                log.error().attr("topic", topicName).log("Can't get last schema for topic using KeyValueSchemaImpl");
                throw new SchemaSerializationException(e.getCause());
            }
            log.info().attr("schema", schemaVersion)

View on GitHub (pinned to 820761864e)

Solutions

  1. Obtain/decode the schema through a ConsumerBuilder/ReaderBuilder with schema configured, so the client sets the SchemaInfoProvider automatically
  2. Set the schema info provider explicitly (schema.setSchemaInfoProvider(...)) if you construct the schema manually
  3. If you only have inline schema info, configure it before decoding so no provider lookup is needed

Example fix

// before
KeyValueSchemaImpl kv = (KeyValueSchemaImpl) Schema.KeyValue(Schema.STRING, Schema.INT32, KeyValueEncodingType.INLINE);
kv.decode(topic, data, schemaVersion); // no provider -> throws
// after
PulsarClient.newClient().newConsumer(Schema.KeyValue(Schema.STRING, Schema.INT32, KeyValueEncodingType.INLINE)).topic(topic)...subscribe(); // consumer installs the provider
Defensive patterns

Strategy: try-catch

Validate before calling

if (schema instanceof KeyValueSchemaImpl && ((KeyValueSchemaImpl<?,?>) schema).getSchemaInfoProvider() == null) { throw new IllegalStateException("KeyValue schema has no SchemaInfoProvider; obtain it from a consumer/reader"); }

Try / catch

try { kv = kvSchema.decode(topic, data, schemaVersion); } catch (SchemaSerializationException e) { if (e.getMessage().contains("SchemaInfoProvider is not set")) { kv = decodeViaConsumer(message); } else throw e; }

Prevention

When it happens

Trigger: Calling decode/fetchSchemaIfNeeded on a standalone KeyValueSchemaImpl (not obtained through a consumer that installed a schemaInfoProvider), or decoding before the consumer finished attaching the provider.

Common situations: Using Schema.KeyValue(...) directly in unit tests or tooling without a ConsumerBuilder schema context; decoding messages offline; auto-schema (Latest/Versioned) KeyValue topics read via a manually constructed schema instance.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/554e8e16046238b4. Report an issue: GitHub.