SchemaInfoImpl instances are treated as immutable even if they are mutable
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
**Describe the bug**
During the development of https://github.com/apache/pulsar/pull/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 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.
Contributor guide
Research direction
Start by reading org.apache.pulsar.client.api.SchemaInfo and SchemaInfoImpl, focusing on the default schema instances and the mutable fields exposed by the examples. Trace every default implementation mentioned by SchemaInfo and identify how clone() and properties behave. Done means the default SchemaInfo implementations are completely immutable and the demonstrated mutations cannot alter shared schema state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100