weaviate / weaviate/java-client

Ensure Builders are only called once and "lock" mutable builder parameters in object constructors.

Open
#405 0 comments 0 reactions 1 assignee View on GitHub

@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:

  1. In all constructors that accept a Builder, wrap all mutable fields (list / map) in their unmodifiable views: Collections.unmodifiableList etc.
  2. Check .build() is only called once per object. Sth like this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.