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); }
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); }