@@ -138,7 +138,18 @@ public Object getPropertyValue(String propertyName, Object object, GraphQLType g
138138 //
139139 // try by public getters name - object.getPropertyName()
140140 try {
141- MethodFinder methodFinder = (rootClass , methodName ) -> findPubliclyAccessibleMethod (cacheKey , rootClass , methodName , dfeInUse );
141+ MethodFinder methodFinder = (rootClass , methodName ) -> findPubliclyAccessibleMethod (cacheKey , rootClass , methodName , dfeInUse , false );
142+ return getPropertyViaGetterMethod (object , propertyName , graphQLType , methodFinder , singleArgumentValue );
143+ } catch (NoSuchMethodException ignored ) {
144+ }
145+ //
146+ // try by public getters name - object.getPropertyName() where its static
147+ try {
148+ // we allow static getXXX() methods because we always have. It's strange in retrospect but
149+ // in order to not break things we allow statics to be used. In theory this double code check is not needed
150+ // because you CANT have a `static getFoo()` and a `getFoo()` in the same class hierarchy but to make the code read clearer
151+ // I have repeated the lookup. Since we cache methods, this happens only once and does not slow us down
152+ MethodFinder methodFinder = (rootClass , methodName ) -> findPubliclyAccessibleMethod (cacheKey , rootClass , methodName , dfeInUse , true );
142153 return getPropertyViaGetterMethod (object , propertyName , graphQLType , methodFinder , singleArgumentValue );
143154 } catch (NoSuchMethodException ignored ) {
144155 }
@@ -215,7 +226,7 @@ private Object getPropertyViaGetterUsingPrefix(Object object, String propertyNam
215226 * which have abstract public interfaces implemented by package-protected
216227 * (generated) subclasses.
217228 */
218- private Method findPubliclyAccessibleMethod (CacheKey cacheKey , Class <?> rootClass , String methodName , boolean dfeInUse ) throws NoSuchMethodException {
229+ private Method findPubliclyAccessibleMethod (CacheKey cacheKey , Class <?> rootClass , String methodName , boolean dfeInUse , boolean allowStaticMethods ) throws NoSuchMethodException {
219230 Class <?> currentClass = rootClass ;
220231 while (currentClass != null ) {
221232 if (Modifier .isPublic (currentClass .getModifiers ())) {
@@ -224,7 +235,7 @@ private Method findPubliclyAccessibleMethod(CacheKey cacheKey, Class<?> rootClas
224235 // try a getter that takes singleArgumentType first (if we have one)
225236 try {
226237 Method method = currentClass .getMethod (methodName , singleArgumentType );
227- if (Modifier . isPublic (method . getModifiers () )) {
238+ if (isSuitablePublicMethod (method , allowStaticMethods )) {
228239 METHOD_CACHE .putIfAbsent (cacheKey , new CachedMethod (method ));
229240 return method ;
230241 }
@@ -233,7 +244,7 @@ private Method findPubliclyAccessibleMethod(CacheKey cacheKey, Class<?> rootClas
233244 }
234245 }
235246 Method method = currentClass .getMethod (methodName );
236- if (Modifier . isPublic (method . getModifiers () )) {
247+ if (isSuitablePublicMethod (method , allowStaticMethods )) {
237248 METHOD_CACHE .putIfAbsent (cacheKey , new CachedMethod (method ));
238249 return method ;
239250 }
@@ -244,6 +255,18 @@ private Method findPubliclyAccessibleMethod(CacheKey cacheKey, Class<?> rootClas
244255 return rootClass .getMethod (methodName );
245256 }
246257
258+ private boolean isSuitablePublicMethod (Method method , boolean allowStaticMethods ) {
259+ int methodModifiers = method .getModifiers ();
260+ if (Modifier .isPublic (methodModifiers )) {
261+ //noinspection RedundantIfStatement
262+ if (Modifier .isStatic (methodModifiers ) && !allowStaticMethods ) {
263+ return false ;
264+ }
265+ return true ;
266+ }
267+ return false ;
268+ }
269+
247270 /*
248271 https://docs.oracle.com/en/java/javase/15/language/records.html
249272
@@ -253,9 +276,11 @@ private Method findPubliclyAccessibleMethod(CacheKey cacheKey, Class<?> rootClas
253276
254277 However, we won't just restrict ourselves strictly to true records. We will find methods that are record like
255278 and fetch them - e.g. `object.propertyName()`
279+
280+ We won't allow static methods for record like methods however
256281 */
257282 private Method findRecordMethod (CacheKey cacheKey , Class <?> rootClass , String methodName ) throws NoSuchMethodException {
258- return findPubliclyAccessibleMethod (cacheKey , rootClass , methodName , false );
283+ return findPubliclyAccessibleMethod (cacheKey , rootClass , methodName , false , false );
259284 }
260285
261286 private Method findViaSetAccessible (CacheKey cacheKey , Class <?> aClass , String methodName , boolean dfeInUse ) throws NoSuchMethodException {
0 commit comments