From be473c2cc8da66291614a81508d3946d9ee33e1d Mon Sep 17 00:00:00 2001 From: Arnab Nandy Date: Wed, 22 Jul 2026 02:17:13 +0530 Subject: [PATCH] Ignore static JavaBean getter methods Closes gh-37068 Signed-off-by: Arnab Nandy --- .../beans/PropertyDescriptorUtils.java | 7 +++++-- ...DescriptorUtilsPropertyResolutionTests.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java index 7fb8ac07181e..2bf6cb2dc1ab 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java @@ -19,6 +19,7 @@ import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; @@ -71,11 +72,13 @@ public static Collection determineBasicProperties( setter = true; nameIndex = 3; } - else if (methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != void.class) { + else if (methodName.startsWith("get") && method.getParameterCount() == 0 && + method.getReturnType() != void.class && !Modifier.isStatic(method.getModifiers())) { setter = false; nameIndex = 3; } - else if (methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class) { + else if (methodName.startsWith("is") && method.getParameterCount() == 0 && + method.getReturnType() == boolean.class && !Modifier.isStatic(method.getModifiers())) { setter = false; nameIndex = 2; } diff --git a/spring-beans/src/test/java/org/springframework/beans/PropertyDescriptorUtilsPropertyResolutionTests.java b/spring-beans/src/test/java/org/springframework/beans/PropertyDescriptorUtilsPropertyResolutionTests.java index 11d772dedb10..f7a9f2f2cb8e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/PropertyDescriptorUtilsPropertyResolutionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/PropertyDescriptorUtilsPropertyResolutionTests.java @@ -69,6 +69,13 @@ void classWithOnlyGetter() { assertReadAndWriteMethodsForClassAndId(pdMap, Number.class, null); } + @Test + void classWithStaticGetters() { + var pdMap = resolver.resolve(ClassWithStaticGetters.class); + + assertThat(pdMap).containsOnlyKeys("class"); + } + @Test void classWithOnlySetter() { var pdMap = resolver.resolve(ClassWithOnlySetter.class); @@ -134,6 +141,17 @@ public Number getId() { } } + static class ClassWithStaticGetters { + + public static Long getId() { + return 42L; + } + + public static boolean isActive() { + return true; + } + } + static class ClassWithOnlySetter { public void setId(Long id) {