Skip to content

Add read and remove methods to ApplicationProperties#1765

Closed
rodmibielli wants to merge 5 commits intospring-io:mainfrom
rodmibielli:main
Closed

Add read and remove methods to ApplicationProperties#1765
rodmibielli wants to merge 5 commits intospring-io:mainfrom
rodmibielli:main

Conversation

@rodmibielli
Copy link
Copy Markdown
Contributor

@rodmibielli rodmibielli commented Mar 15, 2026

Added the following methods to ApplicationProperties:

  • @Nullable Object get(String key)
  • @Nullable T get(String key, Class<T> clazz) which throws if it's the wrong type
  • boolean contains(String key)
  • boolean remove(String key) which returns true if something has been removed

Signed-off-by: Rodrigo Mibielli Peixoto <rodrigo.mibielli@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 15, 2026
Signed-off-by: Rodrigo Mibielli Peixoto <rodrigo.mibielli@gmail.com>
…cation Properties.

Signed-off-by: Rodrigo Mibielli Peixoto <rodrigo.mibielli@gmail.com>
Copy link
Copy Markdown
Contributor

@mhalbritter mhalbritter left a comment

Choose a reason for hiding this comment

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

Hi @rodmibielli , thanks for the PR. I've left some comments for your consideration.

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's the wrong nullable. We use JSpecify's @Nullable.

add(key, (Object) value);
}

/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This JavaDoc is very verbose. Please tone it down a bit, like the existing JavaDoc in the codebase.

void keyNotFoundGetPropertyValue() {
ApplicationProperties properties = new ApplicationProperties();
properties.add("test", "123");
Object value = properties.get("teste");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use something more easily differentiable from test, e.g. not-found.

void getPropertyValueThrowsClassCastException() {
ApplicationProperties properties = new ApplicationProperties();
properties.add("test", 123L);
assertThatThrownBy(() -> properties.get("test", Integer.class)).isInstanceOf(ClassCastException.class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use assertThatExceptionOfType(ClassCastException.class).isThrownBy(...).

void keyNotFoundGetPropertyValueCast() {
ApplicationProperties properties = new ApplicationProperties();
properties.add("test", 123.4);
Double value = properties.get("teste", Double.class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use something more easily differentiable from test, e.g. not-found.

ApplicationProperties properties = new ApplicationProperties();
properties.add("test", "value");
boolean removed = properties.remove("test");
assertThat(removed).isTrue();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also assert that the key is indeed gone.

@mhalbritter mhalbritter self-assigned this Mar 16, 2026
Signed-off-by: Rodrigo Mibielli Peixoto <rodrigo.mibielli@gmail.com>
Signed-off-by: Rodrigo Mibielli Peixoto <rodrigo.mibielli@gmail.com>
@rodmibielli
Copy link
Copy Markdown
Contributor Author

Hey @mhalbritter thank you for the feedback!
I have just commited the changes that you requested.
Please feel free to adjust it further if you whish to.

@mhalbritter mhalbritter changed the title Add read and remove methods to Application Properties. Add read and remove methods to ApplicationProperties Mar 16, 2026
@mhalbritter mhalbritter added type: enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 16, 2026
@mhalbritter mhalbritter added this to the 0.24.0 milestone Mar 16, 2026
mhalbritter pushed a commit that referenced this pull request Mar 16, 2026
See gh-1765

Signed-off-by: Rodrigo Mibielli Peixoto <rodrigo.mibielli@gmail.com>
@mhalbritter
Copy link
Copy Markdown
Contributor

Thanks @rodmibielli !

@mhalbritter
Copy link
Copy Markdown
Contributor

mhalbritter commented Mar 16, 2026

Btw, the next time you open a PR, please do so by creating a branch in your fork and create a PR from that. This way we can merge the PR in a way that GitHub actually shows the PR as merged, not as "red closed". Thanks!

@rodmibielli
Copy link
Copy Markdown
Contributor Author

rodmibielli commented Mar 16, 2026 via email

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.

3 participants