Mutable objects used for immutable values
- Dominant language
- Java
- Stars
- 2.1k
- Forks
- 522
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 137
Description
### Describe the bug
`PolarisEntityCore` type hierarchy is used to represent the persisted (or about to be persisted) state. Especially the already persisted state should be considered immutable. Instances of `PolarisEntityCore` are also cached via `org.apache.polaris.core.persistence.cache.EntityCacheEntry#entity`.
`PolarisEntityCore` + `PolarisBaseEntity` type hierarchy exposes _public_ setters for effectively all properties. This makes it very easy to (accidentally?) _modify_ entity instances that are cached or in any other way shared. Although the types have some "copy constructors", the risk of modifying attributes is still there. Even if a legit change to a property of a shared object would not be correct, given the Java memory model guarantees.
### To Reproduce
_No response_
### Actual Behavior
_No response_
### Expected Behavior
_No response_
### Additional context
_No response_
### System information
_No response_
Contributor guide
Research direction
Start by reviewing the PolarisEntityCore and PolarisBaseEntity hierarchies, their copy constructors, and the EntityCacheEntry#entity usage in the persistence cache. Determine and document the scope of the immutability change before selecting an implementation; done means shared persisted entities cannot be accidentally modified through the exposed API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100