Skip to content

Commit 6d5c502

Browse files
committed
Harden candidate property descriptor checks
Tighten `isCandidateProperty` to reject null descriptors and properties without a read method, instead of treating missing getters as bindable candidates. Tests were updated to cover null and missing-property cases, verify Object-derived `class` is excluded, and confirm a real bindable property (`ServerProperties.port`) is still accepted.
1 parent 233e6dd commit 6d5c502

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

microsphere-spring-boot-core/src/main/java/io/microsphere/spring/boot/context/properties/bind/ConfigurationPropertiesBeanContext.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,14 @@ static String buildPropertyPath(String propertyName, @Nullable String nestedPath
543543
* @return {@code true} if the property is a binding candidate, {@code false} otherwise
544544
*/
545545
static boolean isCandidateProperty(PropertyDescriptor descriptor) {
546+
if (descriptor == null) {
547+
return false;
548+
}
546549
Method readMethod = descriptor.getReadMethod();
547-
return readMethod == null || !Object.class.equals(readMethod.getDeclaringClass());
550+
if (readMethod == null) {
551+
return false;
552+
}
553+
return !Object.class.equals(readMethod.getDeclaringClass());
548554
}
549555

550556
/**

microsphere-spring-boot-core/src/test/java/io/microsphere/spring/boot/context/properties/bind/ConfigurationPropertiesBeanContextTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,18 @@ void testGetInstance() {
146146

147147
@Test
148148
void testIsCandidateProperty() {
149+
assertFalse(isCandidateProperty(null));
149150
PropertyDescriptor descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "name");
150-
assertTrue(isCandidateProperty(descriptor));
151+
assertFalse(isCandidateProperty(descriptor));
152+
153+
descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "not-found");
154+
assertFalse(isCandidateProperty(descriptor));
151155

152156
descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "class");
153157
assertFalse(isCandidateProperty(descriptor));
158+
159+
descriptor = getPropertyDescriptor(ServerProperties.class, "port");
160+
assertTrue(isCandidateProperty(descriptor));
154161
}
155162

156163
@Test

0 commit comments

Comments
 (0)