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.
Describe the bug
During the development of #14508, we noticed that
SchemaInfoImpl(the default implementation ofSchemaInfo) is a non thread-safe mutable object.All the default schema implementations created inside
org.apache.pulsar.client.api.SchemaInfoare creating and saving theSchemaInfoinstance as static field.The issue would be that a thread can access the
SchemaInfoImplimplementation 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
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.