Skip to content

Commit

Permalink
Merge branch '3.0.x' into 3.1.x
Browse files Browse the repository at this point in the history
Closes gh-36448
  • Loading branch information
wilkinsona committed Jul 19, 2023
2 parents 271059c + f145ca0 commit 4d6ee92
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ private boolean isMap(ResolvableType type) {
* @return whether the specified {@code propertyType} is a nested type
*/
private boolean isNestedType(String propertyName, Class<?> propertyType) {
if (this.type.equals(propertyType.getDeclaringClass())) {
Class<?> declaringClass = propertyType.getDeclaringClass();
if (declaringClass != null && declaringClass.isAssignableFrom(this.type)) {
return true;
}
Field field = ReflectionUtils.findField(this.type, propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.boot.context.properties.BoundConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBean;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrarTests.BaseProperties.InheritedNested;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
Expand Down Expand Up @@ -243,6 +244,21 @@ void registerHintsWhenHasPackagePrivateGettersAndSetters() {
"setBravo"));
}

@Test
void registerHintsWhenHasInheritedNestedProperties() {
RuntimeHints runtimeHints = registerHints(ExtendingProperties.class);
assertThat(runtimeHints.reflection().typeHints()).hasSize(3);
assertThat(runtimeHints.reflection().getTypeHint(BaseProperties.class)).satisfies((entry) -> {
assertThat(entry.getMemberCategories()).isEmpty();
assertThat(entry.methods()).extracting(ExecutableHint::getName)
.containsExactlyInAnyOrder("getInheritedNested", "setInheritedNested");
});
assertThat(runtimeHints.reflection().getTypeHint(ExtendingProperties.class))
.satisfies(javaBeanBinding(ExtendingProperties.class, "getBravo", "setBravo"));
assertThat(runtimeHints.reflection().getTypeHint(InheritedNested.class))
.satisfies(javaBeanBinding(InheritedNested.class, "getAlpha", "setAlpha"));
}

private Consumer<TypeHint> javaBeanBinding(Class<?> type, String... expectedMethods) {
return javaBeanBinding(type, type.getDeclaredConstructors()[0], expectedMethods);
}
Expand Down Expand Up @@ -665,4 +681,46 @@ public void setField(String field) {

}

public abstract static class BaseProperties {

private InheritedNested inheritedNested;

public InheritedNested getInheritedNested() {
return this.inheritedNested;
}

public void setInheritedNested(InheritedNested inheritedNested) {
this.inheritedNested = inheritedNested;
}

public static class InheritedNested {

private String alpha;

public String getAlpha() {
return this.alpha;
}

public void setAlpha(String alpha) {
this.alpha = alpha;
}

}

}

public static class ExtendingProperties extends BaseProperties {

private String bravo;

public String getBravo() {
return this.bravo;
}

public void setBravo(String bravo) {
this.bravo = bravo;
}

}

}

0 comments on commit 4d6ee92

Please sign in to comment.