weaviate / weaviate/java-client
Ensure Builders are only called once and "lock" mutable builder parameters in object constructors.
Open
@bevzzz is already working on this.
Since Jul 4, 2025.
v6
- Dominant language
- Java
- Stars
- 34
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
Builders in their current form suffer from a potential misuse where calling a builder setter after calling .build() may alter the state of a previously-create "target" object.
Consider:
var b = new CollectionConfig.Builder("CarelessCollection");
b.properties(Property.text("text_a"));
var cfg = b.build();
// Somewhere later in the code
b.properties(Property.text("text_b"));
client.collections.create(cfg);
CarelessCollection is created with 2 properties, despite what you might expect.
Here's another good illustration of this point: https://github.com/weaviate/java-client/pull/399#discussion_r2179514203
We should:
- In all constructors that accept a Builder, wrap all mutable fields (list / map) in their unmodifiable views:
Collections.unmodifiableListetc. - Check
.build()is only called once per object. Sth like this.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.