Skip to content

Commit e7eb773

Browse files
committed
Use overriding rather than overridden getter methods in config prop AP
Fixes gh-23966
1 parent 79a8335 commit e7eb773

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ private void process(TypeElement element) {
7474
private void processMethod(ExecutableElement method) {
7575
if (isPublic(method)) {
7676
String name = method.getSimpleName().toString();
77-
if (isGetter(method) && !this.publicGetters.containsKey(name)) {
77+
if (isGetter(method) && !this.publicGetters.containsKey(getAccessorName(name))) {
7878
this.publicGetters.put(getAccessorName(name), method);
7979
}
8080
else if (isSetter(method)) {

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolverTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,6 +75,10 @@ void propertiesWithJavaBeanHierarchicalProperties() throws IOException {
7575
PropertyDescriptorResolver resolver = new PropertyDescriptorResolver(metadataEnv);
7676
assertThat(resolver.resolve(type, null).map(PropertyDescriptor::getName)).containsExactly("third",
7777
"second", "first");
78+
assertThat(resolver.resolve(type, null).map(
79+
(descriptor) -> descriptor.getGetter().getEnclosingElement().getSimpleName().toString()))
80+
.containsExactly("HierarchicalProperties", "HierarchicalPropertiesParent",
81+
"HierarchicalPropertiesParent");
7882
assertThat(resolver.resolve(type, null)
7983
.map((descriptor) -> descriptor.resolveItemMetadata("test", metadataEnv))
8084
.map(ItemMetadata::getDefaultValue)).containsExactly("three", "two", "one");

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/HierarchicalPropertiesParent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,8 @@ public void setSecond(String second) {
3333
this.second = second;
3434
}
3535

36-
// Useless override
36+
// Overridden properties should belong to this class, not
37+
// HierarchicalPropertiesGrandparent
3738

3839
@Override
3940
public String getFirst() {

0 commit comments

Comments
 (0)