Skip to content

Missing metadata when using @Name with a constructor-bound property #46599

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ private Stream<PropertyDescriptor> resolveConstructorBoundProperties(TypeElement
private PropertyDescriptor extracted(TypeElement declaringElement, TypeElementMembers members,
VariableElement parameter) {
String name = getPropertyName(parameter);
String parameterName = parameter.getSimpleName().toString();
TypeMirror type = parameter.asType();
ExecutableElement getter = members.getPublicGetter(name, type);
ExecutableElement setter = members.getPublicSetter(name, type);
VariableElement field = members.getFields().get(name);
RecordComponentElement recordComponent = members.getRecordComponents().get(name);
ExecutableElement getter = members.getPublicGetter(parameterName, type);
ExecutableElement setter = members.getPublicSetter(parameterName, type);
VariableElement field = members.getFields().get(parameterName);
RecordComponentElement recordComponent = members.getRecordComponents().get(parameterName);
SourceMetadata sourceMetadata = this.environment.resolveSourceMetadata(field, getter);
PropertyDescriptor propertyDescriptor = (recordComponent != null)
? new RecordParameterPropertyDescriptor(name, type, parameter, declaringElement, getter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ void deprecatedPropertyOnRecord() {
.fromSource(type)
.withDeprecation("some-reason", null, null));
assertThat(metadata).has(Metadata.withProperty("deprecated-record.bravo", String.class).fromSource(type));
assertThat(metadata).has(Metadata.withProperty("deprecated-record.named.charlie", String.class)
.fromSource(type)
.withDeprecation("another-reason", null, null));
}

@Test
Expand Down Expand Up @@ -605,6 +608,8 @@ void recordPropertiesWithDescriptions() {
.withDescription("description without space after asterisk"));
assertThat(metadata).has(Metadata.withProperty("record.descriptions.some-byte", Byte.class)
.withDescription("last description in Javadoc"));
assertThat(metadata).has(Metadata.withProperty("record.descriptions.named.record.component", String.class)
.withDescription("description of a named component"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.configurationsample.record;

import org.springframework.boot.configurationsample.Name;

// @formatter:off

/**
Expand All @@ -26,12 +28,21 @@
* @param someInteger description with @param and @ pitfalls
* @param someBoolean description with extra spaces
* @param someLong description without space after asterisk
* @param namedComponent description of a named component
* @param someByte last description in Javadoc
* @since 1.0.0
* @author Pavel Anisimov
*/
@org.springframework.boot.configurationsample.ConfigurationProperties("record.descriptions")
public record ExampleRecord(String someString, Integer someInteger, Boolean someBoolean, Long someLong, Byte someByte) {
public record ExampleRecord(
String someString,
Integer someInteger,
Boolean someBoolean,
Long someLong,
@Name("named.record.component")
String namedComponent,
Byte someByte
) {
}

//@formatter:on
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@

import org.springframework.boot.configurationsample.ConfigurationProperties;
import org.springframework.boot.configurationsample.DeprecatedConfigurationProperty;
import org.springframework.boot.configurationsample.Name;

/**
* Configuration properties as record with deprecated property.
*
* @param alpha alpha property, deprecated
* @param bravo bravo property
* @param charlie charlie property, named, deprecated
* @author Moritz Halbritter
*/
@ConfigurationProperties("deprecated-record")
public record DeprecatedRecord(String alpha, String bravo) {
public record DeprecatedRecord(String alpha, String bravo, @Name("named.charlie") String charlie) {

@Deprecated
@DeprecatedConfigurationProperty(reason = "some-reason")
public String alpha() {
return this.alpha;
}

@Deprecated
@DeprecatedConfigurationProperty(reason = "another-reason")
public String charlie() {
return this.charlie;
}
}