Skip to content

Fix immutability StreamsBuilderFactory properties#4382

Merged
artembilan merged 3 commits into
spring-projects:mainfrom
jad837:GH-4329_fix_mutableproperties
Apr 6, 2026
Merged

Fix immutability StreamsBuilderFactory properties#4382
artembilan merged 3 commits into
spring-projects:mainfrom
jad837:GH-4329_fix_mutableproperties

Conversation

@jad837

@jad837 jad837 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Fix immuable object sharing across StreamsBuilderFactoryBean

As discussed #4373 (comment), This PR ensures that StreamsBuilderFactoryBean & KafkaStreamsConfiguration always sends a new copy of properties, ensuring immutablility.

Signed-off-by: jad837 <jadhavsaurabh037@gmail.com>
@jad837 jad837 force-pushed the GH-4329_fix_mutableproperties branch from 615f48d to d7b8527 Compare April 1, 2026 17:56
Signed-off-by: jad837 <jadhavsaurabh037@gmail.com>
@jad837 jad837 force-pushed the GH-4329_fix_mutableproperties branch from d7b8527 to a20e6ed Compare April 1, 2026 17:57

@artembilan artembilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any comments why this is in the draft?
Thanks

@Nullable
public Properties getStreamsConfiguration() {
return this.properties; // NOSONAR - inconsistent synchronization
return (Properties) this.properties.clone(); // NOSONAR - inconsistent synchronization

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove that NOSONAR comment!
Not only saying that we don't use it anymore, but also it won't make sense after cloning anyway.

@artembilan artembilan added this to the 4.1.0-RC1 milestone Apr 1, 2026
@jad837 jad837 marked this pull request as ready for review April 2, 2026 14:22
Signed-off-by: jad837 <jadhavsaurabh037@gmail.com>
@jad837 jad837 requested a review from artembilan April 3, 2026 13:29
@artembilan artembilan merged commit 0acbd2b into spring-projects:main Apr 6, 2026
3 checks passed
@artembilan

Copy link
Copy Markdown
Member

@jad837 ,

Thank you!

spring-builds pushed a commit that referenced this pull request Apr 6, 2026
Fixes: #4382

* Fix immutability of KafkaStreamConfiguration properties

* Remove no-sonar from getStreamsConfiguration

Signed-off-by: jad837 <jadhavsaurabh037@gmail.com>

(cherry picked from commit 0acbd2b)
spring-builds pushed a commit that referenced this pull request Apr 6, 2026
Fixes: #4382

* Fix immutability of KafkaStreamConfiguration properties

* Remove no-sonar from getStreamsConfiguration

Signed-off-by: jad837 <jadhavsaurabh037@gmail.com>

(cherry picked from commit 0acbd2b)
jad837 added a commit to jad837/spring-kafka that referenced this pull request Apr 7, 2026
* Replace ConsumerConfig with StreamsConfig
* Update StreamsBuilderFactoryBean logic
* Fix broken group protocol test cases

Signed-off-by: jad837 <jadhavsaurabh037@gmail.com>
artembilan pushed a commit that referenced this pull request Apr 7, 2026
Fixes: #4329

* GH-4329 Added change doc for configuration and whats new
* GH-4329 Fixed group protocol not being added to properties.
Changed group protocol signature to GroupProtocol enum to ensure that correct group protocol is set for beans.
* GH-4329 Updated documentation for Group Protocol usage
* GH-4329 added change doc for configuration and whats new
* GH-4329 Fixed flaky test due to stream config
* GH-4329 Refactor & add warn for group protocol override
* Refactor following GH-4382 backport
* Replace ConsumerConfig with StreamsConfig
* Update StreamsBuilderFactoryBean logic
* Fix broken group protocol test cases
* Refactor to address review comments
* Fix version in docs

Signed-off-by: jad837 <jadhavsaurabh037@gmail.com>
@pdevalck

Copy link
Copy Markdown

The changes cause NPE when the properties are not initialized.

@jad837

jad837 commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Hey @pdevalck is this in case when StreamsBuilderFactoryBean.getProperties() is called? Can you share a bit more on how Can I create this example? I believe this could be when StreamsBuilderFactoryBean is created without any constructor argument... Let me know if I am correct, I can check on this..

@pdevalck

Copy link
Copy Markdown

Yes, you are right. In our integration tests, the constructor without arguments is being called to instantiate te factory. When this happens and we happen to get the streams properties, the NPE happens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants