Class currentClass = root; while (currentClass != null) { String key = mkKey(currentClass, propertyName); Method method = METHOD_CACHE.get(key); if (method != null) {
private Object getPropertyViaFieldAccess(Object object) { Class<?> aClass = object.getClass(); String key = mkKey(aClass, propertyName); try { Field field = FIELD_CACHE.get(key); if (field == null) { field = aClass.getField(propertyName); FIELD_CACHE.putIfAbsent(key, field); } return field.get(object); } catch (NoSuchFieldException e) { if (!USE_SET_ACCESSIBLE.get()) { return null; } // if not public fields then try via setAccessible try { Field field = aClass.getDeclaredField(propertyName); field.setAccessible(true); FIELD_CACHE.putIfAbsent(key, field); return field.get(object); } catch (SecurityException | NoSuchFieldException ignored2) { return null; } catch (IllegalAccessException e1) { throw new GraphQLException(e); } } catch (IllegalAccessException e) { throw new GraphQLException(e); } } }
private Method findViaSetAccessible(Class aClass, String methodName) throws NoSuchMethodException { if (!USE_SET_ACCESSIBLE.get()) { throw new FastNoSuchMethodException(methodName); } String key = mkKey(aClass, propertyName); Method method = METHOD_CACHE.get(key); if (method != null) { return method; } Method[] declaredMethods = aClass.getDeclaredMethods(); Optional<Method> m = Arrays.stream(declaredMethods) .filter(mth -> methodName.equals(mth.getName())) .filter(mth -> hasZeroArgs(mth) || takesDataFetcherEnvironmentAsOnlyArgument(mth)) .sorted(mostMethodArgsFirst()) .findFirst(); if (m.isPresent()) { try { // few JVMs actually enforce this but it might happen method = m.get(); method.setAccessible(true); METHOD_CACHE.putIfAbsent(key, method); return method; } catch (SecurityException ignored) { } } throw new FastNoSuchMethodException(methodName); }
Class currentClass = root; while (currentClass != null) { String key = mkKey(currentClass, propertyName); Method method = METHOD_CACHE.get(key); if (method != null) {
private Object getPropertyViaFieldAccess(Object object) { Class<?> aClass = object.getClass(); String key = mkKey(aClass, propertyName); try { Field field = FIELD_CACHE.get(key); if (field == null) { field = aClass.getField(propertyName); FIELD_CACHE.putIfAbsent(key, field); } return field.get(object); } catch (NoSuchFieldException e) { if (!USE_SET_ACCESSIBLE.get()) { return null; } // if not public fields then try via setAccessible try { Field field = aClass.getDeclaredField(propertyName); field.setAccessible(true); FIELD_CACHE.putIfAbsent(key, field); return field.get(object); } catch (SecurityException | NoSuchFieldException ignored2) { return null; } catch (IllegalAccessException e1) { throw new GraphQLException(e); } } catch (IllegalAccessException e) { throw new GraphQLException(e); } } }
private Method findViaSetAccessible(Class aClass, String methodName) throws NoSuchMethodException { if (!USE_SET_ACCESSIBLE.get()) { throw new FastNoSuchMethodException(methodName); } String key = mkKey(aClass, propertyName); Method method = METHOD_CACHE.get(key); if (method != null) { return method; } Method[] declaredMethods = aClass.getDeclaredMethods(); Optional<Method> m = Arrays.stream(declaredMethods) .filter(mth -> methodName.equals(mth.getName())) .filter(mth -> hasZeroArgs(mth) || takesDataFetcherEnvironmentAsOnlyArgument(mth)) .sorted(mostMethodArgsFirst()) .findFirst(); if (m.isPresent()) { try { // few JVMs actually enforce this but it might happen method = m.get(); method.setAccessible(true); METHOD_CACHE.putIfAbsent(key, method); return method; } catch (SecurityException ignored) { } } throw new FastNoSuchMethodException(methodName); }