Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow resolving nested placeholders if value is not String but CharSequence #32876

Closed
wants to merge 1 commit into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented May 23, 2024

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 23, 2024
@snicoll snicoll added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 23, 2024
@snicoll snicoll self-assigned this May 23, 2024
@snicoll snicoll added this to the 6.2.0-M4 milestone May 23, 2024
@snicoll snicoll closed this in 3b2a4da May 23, 2024
@snicoll
Copy link
Member

snicoll commented May 23, 2024

Ironically enough, that broke the use case in the linked issue as anything that implements CharSequence now is going to be handled as a String down the road and the proper conversion won't happen as expected.

Reverting.

@snicoll snicoll reopened this May 23, 2024
@snicoll snicoll removed this from the 6.2.0-M4 milestone May 23, 2024
@snicoll snicoll added the status: declined A suggestion or change that we don't feel we should currently apply label May 23, 2024
snicoll added a commit that referenced this pull request May 23, 2024
This reverts commit 3b2a4da, reversing
changes made to 181b680.

See gh-32876
@snicoll
Copy link
Member

snicoll commented May 23, 2024

This was reverted in 94348d9

@snicoll snicoll closed this May 23, 2024
@quaff
Copy link
Contributor Author

quaff commented May 24, 2024

Ironically enough, that broke the use case in the linked issue as anything that implements CharSequence now is going to be handled as a String down the road and the proper conversion won't happen as expected.

Reverting.

Could you elaborate what is broken? CharSequence is an interface, returned String object implementing that interface seems correct.

@snicoll
Copy link
Member

snicoll commented May 24, 2024

You could try your change against the change you've made in Spring Boot and you'll see by yourself.

@quaff
Copy link
Contributor Author

quaff commented May 24, 2024

You could try your change against the change you've made in Spring Boot and you'll see by yourself.

		MockPropertySource propertySource = new MockPropertySource();
		propertySource.withProperty("v1", "1");
		propertySource.withProperty("v2", new CharSequence() {

			static final String underlying = "${v1}";

			@Override
			public int length() {
				return underlying.length();
			}

			@Override
			public char charAt(int index) {
				return underlying.charAt(index);
			}

			@Override
			public CharSequence subSequence(int start, int end) {
				return underlying.subSequence(start, end);
			}

			@Override
			public String toString() {
				return underlying;
			}
		});
		environment.getPropertySources().addFirst(propertySource);
		assertThat(environment.getProperty("v2")).isEqualTo("1");
		assertThat(environment.getProperty("v2", Integer.class)).isOne();

The v2 is equal to ${v1} before. after this changes, it's expected 1, and I tried value from ConfigTreePropertySource is resolved too, what's the problem here?

@snicoll
Copy link
Member

snicoll commented May 24, 2024

You're missing the point, it's the other way around. org.springframework.boot.env.ConfigTreePropertySource.Value implements CharSequence and now goes through the instance of check that this PR changed rather than being handled as a Value.

@quaff
Copy link
Contributor Author

quaff commented May 24, 2024

You're missing the point, it's the other way around. org.springframework.boot.env.ConfigTreePropertySource.Value implements CharSequence and now goes through the instance of check that this PR changed rather than being handled as a Value.

I'm aware of that, I don't think application would rely on type Value since it's kind of internal type.

@quaff
Copy link
Contributor Author

quaff commented May 31, 2024

You're missing the point, it's the other way around. org.springframework.boot.env.ConfigTreePropertySource.Value implements CharSequence and now goes through the instance of check that this PR changed rather than being handled as a Value.

@snicoll Please see spring-projects/spring-boot#40862 (comment), I will submit another PR if that fix is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants