Skip to content

SchemaInfoImpl instances are treated as immutable even if they are mutable #14522

Description

@nicoloboschi

Describe the bug
During the development of #14508, we noticed that SchemaInfoImpl (the default implementation of SchemaInfo) is a non thread-safe mutable object.

All the default schema implementations created inside org.apache.pulsar.client.api.SchemaInfo are creating and saving the SchemaInfo instance as static field.
The issue would be that a thread can access the SchemaInfoImpl implementation and modify the fields, leading to unexpected behaviours.

Another clue that says that the SchemaInfo is supposed to be immutable is that the implementation of the clone() method just return the same instance.

To Reproduce

final Schema<Integer> integerSchema = Schema.INT32;
// example 1
((SchemaInfoImpl) integerSchema.getSchemaInfo()).getProperties().clear();
// example 2
((SchemaInfoImpl) integerSchema.getSchemaInfo()).setProperties(map);
// example 3
((SchemaInfoImpl) integerSchema.getSchemaInfo()).setType(SchemaType.BYTES);

Expected behavior
SchemaInfo default implementations are supposed to be completely immutable, avoiding unpredictable side effects.

Additional context
It applies to all the active branches, even master branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions