org.springframework.util.ReflectionUtils.makeAccessible()

Here are the examples of the java api org.springframework.util.ReflectionUtils.makeAccessible() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

261 Examples 7

19 View Source File : SpringBeanTaskUtil.java
License : GNU Affero General Public License v3.0
Project Creator : zycSummer

public static void invokeMethod(ScheduleJob scheduleJob) {
    Object target = SpringContextUtils.getBean(scheduleJob.getBeanName());
    try {
        if (StrUtil.isNotEmpty(scheduleJob.getParams())) {
            Method method = target.getClreplaced().getDeclaredMethod(scheduleJob.getMethodName(), String.clreplaced);
            ReflectionUtils.makeAccessible(method);
            method.invoke(target, scheduleJob.getParams());
        } else {
            Method method = target.getClreplaced().getDeclaredMethod(scheduleJob.getMethodName());
            ReflectionUtils.makeAccessible(method);
            method.invoke(target);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("执行定时任务失败", e);
    }
}

19 View Source File : MyRedisCacheManager.java
License : Apache License 2.0
Project Creator : Zoctan

private void add(final Clreplaced clazz) {
    ReflectionUtils.doWithMethods(clazz, method -> {
        ReflectionUtils.makeAccessible(method);
        final CacheExpire cacheExpire = AnnotationUtils.findAnnotation(method, CacheExpire.clreplaced);
        if (cacheExpire == null) {
            return;
        }
        final Cacheable cacheable = AnnotationUtils.findAnnotation(method, Cacheable.clreplaced);
        if (cacheable != null) {
            this.add(cacheable.cacheNames(), cacheExpire);
            return;
        }
        final Caching caching = AnnotationUtils.findAnnotation(method, Caching.clreplaced);
        if (caching != null) {
            final Cacheable[] cs = caching.cacheable();
            if (cs.length > 0) {
                for (final Cacheable c : cs) {
                    if (c != null) {
                        this.add(c.cacheNames(), cacheExpire);
                    }
                }
            }
        } else {
            final CacheConfig cacheConfig = AnnotationUtils.findAnnotation(clazz, CacheConfig.clreplaced);
            if (cacheConfig != null) {
                this.add(cacheConfig.cacheNames(), cacheExpire);
            }
        }
    }, method -> null != AnnotationUtils.findAnnotation(method, CacheExpire.clreplaced));
}

19 View Source File : MyRedisCacheManager.java
License : Apache License 2.0
Project Creator : Zoctan

private void add(final Clreplaced clazz) {
    ReflectionUtils.doWithMethods(clazz, method -> {
        ReflectionUtils.makeAccessible(method);
        final CacheExpire cacheExpire = AnnotationUtils.findAnnotation(method, CacheExpire.clreplaced);
        if (!Optional.ofNullable(cacheExpire).isPresent()) {
            return;
        }
        final Cacheable cacheable = AnnotationUtils.findAnnotation(method, Cacheable.clreplaced);
        if (Optional.ofNullable(cacheable).isPresent()) {
            this.add(cacheable.cacheNames(), cacheExpire);
            return;
        }
        final Caching caching = AnnotationUtils.findAnnotation(method, Caching.clreplaced);
        if (Optional.ofNullable(caching).isPresent()) {
            final Cacheable[] cs = caching.cacheable();
            if (cs.length > 0) {
                for (final Cacheable c : cs) {
                    if (Optional.ofNullable(c).isPresent()) {
                        this.add(c.cacheNames(), cacheExpire);
                    }
                }
            }
        } else {
            final CacheConfig cacheConfig = AnnotationUtils.findAnnotation(clazz, CacheConfig.clreplaced);
            if (Optional.ofNullable(cacheConfig).isPresent()) {
                this.add(cacheConfig.cacheNames(), cacheExpire);
            }
        }
    }, method -> null != AnnotationUtils.findAnnotation(method, CacheExpire.clreplaced));
}

19 View Source File : SecurityTest.java
License : MIT License
Project Creator : zidoshare

private PhoneCodeCache getCache() {
    Method getHttp = ReflectionUtils.findMethod(SpringBootRestSecurityConfiguration.DefaultRestSecurityConfigurerAdapter.clreplaced, "getHttp");
    replacedert.replacedertNotNull(getHttp);
    ReflectionUtils.makeAccessible(getHttp);
    SpringBootRestSecurityConfiguration.DefaultRestSecurityConfigurerAdapter configure = context.getBean(SpringBootRestSecurityConfiguration.DefaultRestSecurityConfigurerAdapter.clreplaced);
    HttpSecurity http = (HttpSecurity) ReflectionUtils.invokeMethod(getHttp, configure);
    replacedert.replacedertNotNull(http);
    return http.getSharedObject(PhoneCodeCache.clreplaced);
}

19 View Source File : ScheduleRunnable.java
License : Apache License 2.0
Project Creator : zhupanlinch

@Override
public void run() {
    try {
        ReflectionUtils.makeAccessible(method);
        if (StringUtils.isNotBlank(params)) {
            method.invoke(target, params);
        } else {
            method.invoke(target);
        }
    } catch (Exception e) {
        throw new MyException("执行定时任务失败", e);
    }
}

19 View Source File : PrivateHelper.java
License : Apache License 2.0
Project Creator : zhoutaoo

/**
 * 将么有方法设置为可访问,并调用该方法
 *
 * @param instance 实例对象
 * @param method   方法对象
 * @param args
 */
public Object invokePrivateMethod(Object instance, Method method, Object... args) {
    ReflectionUtils.makeAccessible(method);
    return ReflectionUtils.invokeMethod(method, instance, args);
}

19 View Source File : PrivateHelper.java
License : Apache License 2.0
Project Creator : zhoutaoo

/**
 * @param instance  实例对象
 * @param fieldName 成员变量名
 * @param value     值
 */
public void setPrivateField(Object instance, String fieldName, Object value) {
    Field signingKeyField = ReflectionUtils.findField(instance.getClreplaced(), fieldName);
    ReflectionUtils.makeAccessible(signingKeyField);
    ReflectionUtils.setField(signingKeyField, instance, value);
}

19 View Source File : ScheduleRunnable.java
License : GNU Affero General Public License v3.0
Project Creator : zhouhuan751312

@Override
public void run() {
    try {
        ReflectionUtils.makeAccessible(method);
        if (ToolUtil.isNotEmpty(params)) {
            method.invoke(target, params);
        } else {
            method.invoke(target);
        }
    } catch (Exception e) {
        throw new RxcException("执行定时任务失败", e);
    }
}

19 View Source File : ScheduleRunnable.java
License : MIT License
Project Creator : ZhiYiDai

@Override
public void run() {
    try {
        ReflectionUtils.makeAccessible(method);
        if (StringUtils.isNotBlank(params)) {
            method.invoke(target, params);
        } else {
            method.invoke(target);
        }
    } catch (Exception e) {
    // 执行定时任务失败
    }
}

19 View Source File : ScheduleRunnable.java
License : GNU General Public License v3.0
Project Creator : zhaoqicheng

@Override
public void run() {
    try {
        ReflectionUtils.makeAccessible(method);
        if (StringUtils.isNotBlank(params)) {
            method.invoke(target, params);
        } else {
            method.invoke(target);
        }
    } catch (Exception e) {
        throw new RRException("执行定时任务失败", e);
    }
}

19 View Source File : TypeExcludeFiltersContextCustomizer.java
License : Apache License 2.0
Project Creator : yuanmabiji

private TypeExcludeFilter instantiateTypeExcludeFilter(Clreplaced<?> testClreplaced, Clreplaced<?> filterClreplaced) {
    try {
        Constructor<?> constructor = getTypeExcludeFilterConstructor(filterClreplaced);
        ReflectionUtils.makeAccessible(constructor);
        if (constructor.getParameterCount() == 1) {
            return (TypeExcludeFilter) constructor.newInstance(testClreplaced);
        }
        return (TypeExcludeFilter) constructor.newInstance();
    } catch (Exception ex) {
        throw new IllegalStateException("Unable to create filter for " + filterClreplaced, ex);
    }
}

19 View Source File : TestRestTemplate.java
License : Apache License 2.0
Project Creator : yuanmabiji

private Clreplaced<? extends ClientHttpRequestFactory> getRequestFactoryClreplaced(RestTemplate restTemplate) {
    ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
    if (InterceptingClientHttpRequestFactory.clreplaced.isreplacedignableFrom(requestFactory.getClreplaced())) {
        Field requestFactoryField = ReflectionUtils.findField(RestTemplate.clreplaced, "requestFactory");
        ReflectionUtils.makeAccessible(requestFactoryField);
        requestFactory = (ClientHttpRequestFactory) ReflectionUtils.getField(requestFactoryField, restTemplate);
    }
    return requestFactory.getClreplaced();
}

19 View Source File : MockitoTestExecutionListener.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void reinjectFields(final TestContext testContext) {
    postProcessFields(testContext, (mockitoField, postProcessor) -> {
        ReflectionUtils.makeAccessible(mockitoField.field);
        ReflectionUtils.setField(mockitoField.field, testContext.getTestInstance(), null);
        postProcessor.inject(mockitoField.field, mockitoField.target, mockitoField.definition);
    });
}

19 View Source File : ClassLoaderFilesResourcePatternResolver.java
License : Apache License 2.0
Project Creator : yuanmabiji

private ResourceLoader retrieveResourceLoader(ApplicationContext applicationContext) {
    Field field = ReflectionUtils.findField(applicationContext.getClreplaced(), "resourceLoader", ResourceLoader.clreplaced);
    if (field == null) {
        return null;
    }
    ReflectionUtils.makeAccessible(field);
    return (ResourceLoader) ReflectionUtils.getField(field, applicationContext);
}

19 View Source File : HateoasObjenesisCacheDisabler.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void removeObjenesisCache(Clreplaced<?> dummyInvocationUtils) {
    try {
        Field objenesisField = ReflectionUtils.findField(dummyInvocationUtils, "OBJENESIS");
        if (objenesisField != null) {
            ReflectionUtils.makeAccessible(objenesisField);
            Object objenesis = ReflectionUtils.getField(objenesisField, null);
            Field cacheField = ReflectionUtils.findField(objenesis.getClreplaced(), "cache");
            ReflectionUtils.makeAccessible(cacheField);
            ReflectionUtils.setField(cacheField, objenesis, null);
        }
    } catch (Exception ex) {
        logger.warn("Failed to disable Spring HATEOAS's Objenesis cache. ClreplacedCastExceptions may occur", ex);
    }
}

19 View Source File : ReflectiveOperationInvoker.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public Object invoke(InvocationContext context) {
    validateRequiredParameters(context);
    Method method = this.operationMethod.getMethod();
    Object[] resolvedArguments = resolveArguments(context);
    ReflectionUtils.makeAccessible(method);
    return ReflectionUtils.invokeMethod(method, this.target, resolvedArguments);
}

19 View Source File : UndertowWebServer.java
License : Apache License 2.0
Project Creator : yuanmabiji

private UndertowWebServer.Port getPortFromListener(Object listener) {
    Field typeField = ReflectionUtils.findField(listener.getClreplaced(), "type");
    ReflectionUtils.makeAccessible(typeField);
    String protocol = ReflectionUtils.getField(typeField, listener).toString();
    Field portField = ReflectionUtils.findField(listener.getClreplaced(), "port");
    ReflectionUtils.makeAccessible(portField);
    int port = (Integer) ReflectionUtils.getField(portField, listener);
    return new UndertowWebServer.Port(port, protocol);
}

19 View Source File : UndertowServletWebServer.java
License : Apache License 2.0
Project Creator : yuanmabiji

private Port getPortFromListener(Object listener) {
    Field typeField = ReflectionUtils.findField(listener.getClreplaced(), "type");
    ReflectionUtils.makeAccessible(typeField);
    String protocol = ReflectionUtils.getField(typeField, listener).toString();
    Field portField = ReflectionUtils.findField(listener.getClreplaced(), "port");
    ReflectionUtils.makeAccessible(portField);
    int port = (Integer) ReflectionUtils.getField(portField, listener);
    return new Port(port, protocol);
}

19 View Source File : FailureAnalyzers.java
License : Apache License 2.0
Project Creator : yuanmabiji

private List<Failurereplacedyzer> loadFailurereplacedyzers(ClreplacedLoader clreplacedLoader) {
    List<String> replacedyzerNames = SpringFactoriesLoader.loadFactoryNames(Failurereplacedyzer.clreplaced, clreplacedLoader);
    List<Failurereplacedyzer> replacedyzers = new ArrayList<>();
    for (String replacedyzerName : replacedyzerNames) {
        try {
            Constructor<?> constructor = ClreplacedUtils.forName(replacedyzerName, clreplacedLoader).getDeclaredConstructor();
            ReflectionUtils.makeAccessible(constructor);
            replacedyzers.add((Failurereplacedyzer) constructor.newInstance());
        } catch (Throwable ex) {
            logger.trace("Failed to load " + replacedyzerName, ex);
        }
    }
    AnnotationAwareOrderComparator.sort(replacedyzers);
    return replacedyzers;
}

19 View Source File : InjectAnnotationParserHolderImpl.java
License : Apache License 2.0
Project Creator : Yiuman

@Override
public void inject(Object target) {
    Clreplaced<?> targetClreplaced = target.getClreplaced();
    try {
        for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(targetClreplaced)) {
            if ("clreplaced".equals(pd.getName())) {
                continue;
            }
            Field field = ReflectionUtils.findField(targetClreplaced, pd.getName());
            ReflectionUtils.makeAccessible(field);
            Method writeMethod = pd.getWriteMethod();
            ReflectionUtils.makeAccessible(writeMethod);
            List<Annotation> fieldAnnotations = Arrays.asList(field.getDeclaredAnnotations());
            fieldAnnotations.addAll(Arrays.asList(writeMethod.getDeclaredAnnotations()));
            if (!CollectionUtils.isEmpty(fieldAnnotations)) {
                fieldAnnotations.parallelStream().filter(annotation -> INJECT_ANNOTATIONS.contains(ClreplacedUtils.getRealClreplaced(annotation.getClreplaced()))).forEach(LambdaUtils.consumerWrapper(annotation -> {
                    // todo 这里需要优化类型转化
                    Object parseValue = parse(annotation);
                    writeMethod.invoke(target, parseValue);
                }));
            }
        }
    } catch (Exception e) {
        log.info("注解注入器注入失败", e);
    }
}

19 View Source File : GrpcClientBeanPostProcessor.java
License : MIT License
Project Creator : yidongnan

@Override
public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
    Clreplaced<?> clazz = bean.getClreplaced();
    do {
        for (final Field field : clazz.getDeclaredFields()) {
            final GrpcClient annotation = AnnotationUtils.findAnnotation(field, GrpcClient.clreplaced);
            if (annotation != null) {
                ReflectionUtils.makeAccessible(field);
                ReflectionUtils.setField(field, bean, processInjectionPoint(field, field.getType(), annotation));
            }
        }
        for (final Method method : clazz.getDeclaredMethods()) {
            final GrpcClient annotation = AnnotationUtils.findAnnotation(method, GrpcClient.clreplaced);
            if (annotation != null) {
                final Clreplaced<?>[] paramTypes = method.getParameterTypes();
                if (paramTypes.length != 1) {
                    throw new BeanDefinitionStoreException("Method " + method + " doesn't have exactly one parameter.");
                }
                ReflectionUtils.makeAccessible(method);
                ReflectionUtils.invokeMethod(method, bean, processInjectionPoint(method, paramTypes[0], annotation));
            }
        }
        clazz = clazz.getSuperclreplaced();
    } while (clazz != null);
    return bean;
}

19 View Source File : ReflectUtils.java
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus

public static void invokeMethod(Object target, String methodName, Clreplaced[] param, Object... args) {
    Method method = ReflectionUtils.findMethod(target.getClreplaced(), methodName, param);
    ReflectionUtils.makeAccessible(method);
    ReflectionUtils.invokeMethod(method, target, args);
}

19 View Source File : ReflectUtils.java
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus

public static <T> T invokeMethod(Object target, String methodName) {
    Method method = ReflectionUtils.findMethod(target.getClreplaced(), methodName);
    ReflectionUtils.makeAccessible(method);
    return (T) ReflectionUtils.invokeMethod(method, target);
}

19 View Source File : ReflectUtils.java
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus

public static void setFieldValue(Object target, String fieldName, Object value) {
    Field field = ReflectionUtils.findField(target.getClreplaced(), fieldName);
    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, target, value);
}

19 View Source File : ReflectUtils.java
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus

public static Object getFieldObject(Object target, String fieldName) {
    Field field = ReflectionUtils.findField(target.getClreplaced(), fieldName);
    ReflectionUtils.makeAccessible(field);
    return ReflectionUtils.getField(field, target);
}

19 View Source File : ReflectUtils.java
License : GNU Lesser General Public License v3.0
Project Creator : vision-consensus

public static <T> T getFieldValue(Object target, String fieldName) {
    Field field = ReflectionUtils.findField(target.getClreplaced(), fieldName);
    ReflectionUtils.makeAccessible(field);
    return (T) ReflectionUtils.getField(field, target);
}

19 View Source File : QuartzRunnable.java
License : Apache License 2.0
Project Creator : vip-efactory

@Override
public Object call() throws Exception {
    ReflectionUtils.makeAccessible(method);
    if (StringUtils.isNotBlank(params)) {
        method.invoke(target, params);
    } else {
        method.invoke(target);
    }
    return null;
}

19 View Source File : ContentDispositionTests.java
License : MIT License
Project Creator : Vip-Augus

// SPR-14547
@Test
public void encodeHeaderFieldParam() {
    Method encode = ReflectionUtils.findMethod(ContentDisposition.clreplaced, "encodeHeaderFieldParam", String.clreplaced, Charset.clreplaced);
    ReflectionUtils.makeAccessible(encode);
    String result = (String) ReflectionUtils.invokeMethod(encode, null, "test.txt", StandardCharsets.US_ASCII);
    replacedertEquals("test.txt", result);
    result = (String) ReflectionUtils.invokeMethod(encode, null, "中文.txt", StandardCharsets.UTF_8);
    replacedertEquals("UTF-8''%E4%B8%AD%E6%96%87.txt", result);
}

19 View Source File : ContentDispositionTests.java
License : MIT License
Project Creator : Vip-Augus

@Test(expected = IllegalArgumentException.clreplaced)
public void decodeHeaderFieldParamInvalidCharset() {
    Method decode = ReflectionUtils.findMethod(ContentDisposition.clreplaced, "decodeHeaderFieldParam", String.clreplaced);
    ReflectionUtils.makeAccessible(decode);
    ReflectionUtils.invokeMethod(decode, null, "UTF-16''test");
}

19 View Source File : ContentDispositionTests.java
License : MIT License
Project Creator : Vip-Augus

@Test(expected = IllegalArgumentException.clreplaced)
public void encodeHeaderFieldParamInvalidCharset() {
    Method encode = ReflectionUtils.findMethod(ContentDisposition.clreplaced, "encodeHeaderFieldParam", String.clreplaced, Charset.clreplaced);
    ReflectionUtils.makeAccessible(encode);
    ReflectionUtils.invokeMethod(encode, null, "test", StandardCharsets.UTF_16);
}

19 View Source File : ContentDispositionTests.java
License : MIT License
Project Creator : Vip-Augus

// SPR-14408
@Test
public void decodeHeaderFieldParam() {
    Method decode = ReflectionUtils.findMethod(ContentDisposition.clreplaced, "decodeHeaderFieldParam", String.clreplaced);
    ReflectionUtils.makeAccessible(decode);
    String result = (String) ReflectionUtils.invokeMethod(decode, null, "test.txt");
    replacedertEquals("test.txt", result);
    result = (String) ReflectionUtils.invokeMethod(decode, null, "UTF-8''%E4%B8%AD%E6%96%87.txt");
    replacedertEquals("中文.txt", result);
}

19 View Source File : InvocableHandlerMethod.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Invoke the handler method with the given argument values.
 * 执行处理器方法
 */
@Nullable
protected Object doInvoke(Object... args) throws Exception {
    ReflectionUtils.makeAccessible(getBridgedMethod());
    try {
        return getBridgedMethod().invoke(getBean(), args);
    } catch (IllegalArgumentException ex) {
        replacedertTargetBean(getBridgedMethod(), getBean(), args);
        String text = (ex.getMessage() != null ? ex.getMessage() : "Illegal argument");
        throw new IllegalStateException(formatInvokeError(text, args), ex);
    } catch (InvocationTargetException ex) {
        // Unwrap for HandlerExceptionResolvers ...
        Throwable targetException = ex.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw (RuntimeException) targetException;
        } else if (targetException instanceof Error) {
            throw (Error) targetException;
        } else if (targetException instanceof Exception) {
            throw (Exception) targetException;
        } else {
            throw new IllegalStateException(formatInvokeError("Invocation failure", args), targetException);
        }
    }
}

19 View Source File : ReflectionTestUtils.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Get the value of the {@linkplain Field field} with the given {@code name}
 * from the provided {@code targetObject}/{@code targetClreplaced}.
 * <p>If the supplied {@code targetObject} is a <em>proxy</em>, it will
 * be {@linkplain AopTestUtils#getUltimateTargetObject unwrapped} allowing
 * the field to be retrieved from the ultimate target of the proxy.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * field. In addition, an attempt will be made to make non-{@code public}
 * fields <em>accessible</em>, thus allowing one to get {@code protected},
 * {@code private}, and <em>package-private</em> fields.
 * @param targetObject the target object from which to get the field; may be
 * {@code null} if the field is static
 * @param targetClreplaced the target clreplaced from which to get the field; may
 * be {@code null} if the field is an instance field
 * @param name the name of the field to get; never {@code null}
 * @return the field's current value
 * @since 4.2
 * @see #getField(Object, String)
 * @see #getField(Clreplaced, String)
 * @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
 * @see ReflectionUtils#makeAccessible(Field)
 * @see ReflectionUtils#getField(Field, Object)
 * @see AopTestUtils#getUltimateTargetObject(Object)
 */
@Nullable
public static Object getField(@Nullable Object targetObject, @Nullable Clreplaced<?> targetClreplaced, String name) {
    replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
    if (targetObject != null && springAopPresent) {
        targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
    }
    if (targetClreplaced == null) {
        targetClreplaced = targetObject.getClreplaced();
    }
    Field field = ReflectionUtils.findField(targetClreplaced, name);
    if (field == null) {
        throw new IllegalArgumentException(String.format("Could not find field '%s' on %s or target clreplaced [%s]", name, safeToString(targetObject), targetClreplaced));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Getting field '%s' from %s or target clreplaced [%s]", name, safeToString(targetObject), targetClreplaced));
    }
    ReflectionUtils.makeAccessible(field);
    return ReflectionUtils.getField(field, targetObject);
}

19 View Source File : ReflectionTestUtils.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Set the {@linkplain Field field} with the given {@code name}/{@code type}
 * on the provided {@code targetObject}/{@code targetClreplaced} to the supplied
 * {@code value}.
 * <p>If the supplied {@code targetObject} is a <em>proxy</em>, it will
 * be {@linkplain AopTestUtils#getUltimateTargetObject unwrapped} allowing
 * the field to be set on the ultimate target of the proxy.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * field. In addition, an attempt will be made to make non-{@code public}
 * fields <em>accessible</em>, thus allowing one to set {@code protected},
 * {@code private}, and <em>package-private</em> fields.
 * @param targetObject the target object on which to set the field; may be
 * {@code null} if the field is static
 * @param targetClreplaced the target clreplaced on which to set the field; may
 * be {@code null} if the field is an instance field
 * @param name the name of the field to set; may be {@code null} if
 * {@code type} is specified
 * @param value the value to set
 * @param type the type of the field to set; may be {@code null} if
 * {@code name} is specified
 * @since 4.2
 * @see ReflectionUtils#findField(Clreplaced, String, Clreplaced)
 * @see ReflectionUtils#makeAccessible(Field)
 * @see ReflectionUtils#setField(Field, Object, Object)
 * @see AopTestUtils#getUltimateTargetObject(Object)
 */
public static void setField(@Nullable Object targetObject, @Nullable Clreplaced<?> targetClreplaced, @Nullable String name, @Nullable Object value, @Nullable Clreplaced<?> type) {
    replacedert.isTrue(targetObject != null || targetClreplaced != null, "Either targetObject or targetClreplaced for the field must be specified");
    if (targetObject != null && springAopPresent) {
        targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
    }
    if (targetClreplaced == null) {
        targetClreplaced = targetObject.getClreplaced();
    }
    Field field = ReflectionUtils.findField(targetClreplaced, name, type);
    if (field == null) {
        throw new IllegalArgumentException(String.format("Could not find field '%s' of type [%s] on %s or target clreplaced [%s]", name, type, safeToString(targetObject), targetClreplaced));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Setting field '%s' of type [%s] on %s or target clreplaced [%s] to value [%s]", name, type, safeToString(targetObject), targetClreplaced, value));
    }
    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, targetObject, value);
}

19 View Source File : ReflectionTestUtils.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Invoke the setter method with the given {@code name} on the supplied
 * target object with the supplied {@code value}.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * method. In addition, an attempt will be made to make non-{@code public}
 * methods <em>accessible</em>, thus allowing one to invoke {@code protected},
 * {@code private}, and <em>package-private</em> setter methods.
 * <p>In addition, this method supports JavaBean-style <em>property</em>
 * names. For example, if you wish to set the {@code name} property on the
 * target object, you may preplaced either "name" or
 * "setName" as the method name.
 * @param target the target object on which to invoke the specified setter
 * method
 * @param name the name of the setter method to invoke or the corresponding
 * property name
 * @param value the value to provide to the setter method
 * @param type the formal parameter type declared by the setter method
 * @see ReflectionUtils#findMethod(Clreplaced, String, Clreplaced[])
 * @see ReflectionUtils#makeAccessible(Method)
 * @see ReflectionUtils#invokeMethod(Method, Object, Object[])
 */
public static void invokeSetterMethod(Object target, String name, @Nullable Object value, @Nullable Clreplaced<?> type) {
    replacedert.notNull(target, "Target object must not be null");
    replacedert.hasText(name, "Method name must not be empty");
    Clreplaced<?>[] paramTypes = (type != null ? new Clreplaced<?>[] { type } : null);
    String setterMethodName = name;
    if (!name.startsWith(SETTER_PREFIX)) {
        setterMethodName = SETTER_PREFIX + StringUtils.capitalize(name);
    }
    Method method = ReflectionUtils.findMethod(target.getClreplaced(), setterMethodName, paramTypes);
    if (method == null && !setterMethodName.equals(name)) {
        setterMethodName = name;
        method = ReflectionUtils.findMethod(target.getClreplaced(), setterMethodName, paramTypes);
    }
    if (method == null) {
        throw new IllegalArgumentException(String.format("Could not find setter method '%s' on %s with parameter type [%s]", setterMethodName, safeToString(target), type));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Invoking setter method '%s' on %s with value [%s]", setterMethodName, safeToString(target), value));
    }
    ReflectionUtils.makeAccessible(method);
    ReflectionUtils.invokeMethod(method, target, value);
}

19 View Source File : ReflectionTestUtils.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Invoke the getter method with the given {@code name} on the supplied
 * target object with the supplied {@code value}.
 * <p>This method traverses the clreplaced hierarchy in search of the desired
 * method. In addition, an attempt will be made to make non-{@code public}
 * methods <em>accessible</em>, thus allowing one to invoke {@code protected},
 * {@code private}, and <em>package-private</em> getter methods.
 * <p>In addition, this method supports JavaBean-style <em>property</em>
 * names. For example, if you wish to get the {@code name} property on the
 * target object, you may preplaced either "name" or
 * "getName" as the method name.
 * @param target the target object on which to invoke the specified getter
 * method
 * @param name the name of the getter method to invoke or the corresponding
 * property name
 * @return the value returned from the invocation
 * @see ReflectionUtils#findMethod(Clreplaced, String, Clreplaced[])
 * @see ReflectionUtils#makeAccessible(Method)
 * @see ReflectionUtils#invokeMethod(Method, Object, Object[])
 */
@Nullable
public static Object invokeGetterMethod(Object target, String name) {
    replacedert.notNull(target, "Target object must not be null");
    replacedert.hasText(name, "Method name must not be empty");
    String getterMethodName = name;
    if (!name.startsWith(GETTER_PREFIX)) {
        getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
    }
    Method method = ReflectionUtils.findMethod(target.getClreplaced(), getterMethodName);
    if (method == null && !getterMethodName.equals(name)) {
        getterMethodName = name;
        method = ReflectionUtils.findMethod(target.getClreplaced(), getterMethodName);
    }
    if (method == null) {
        throw new IllegalArgumentException(String.format("Could not find getter method '%s' on %s", getterMethodName, safeToString(target)));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Invoking getter method '%s' on %s", getterMethodName, safeToString(target)));
    }
    ReflectionUtils.makeAccessible(method);
    return ReflectionUtils.invokeMethod(method, target);
}

19 View Source File : TestContextManager.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Attempt to create a copy of the supplied {@code TestContext} using its
 * <em>copy constructor</em>.
 */
private static TestContext copyTestContext(TestContext testContext) {
    Constructor<? extends TestContext> constructor = ClreplacedUtils.getConstructorIfAvailable(testContext.getClreplaced(), testContext.getClreplaced());
    if (constructor != null) {
        try {
            ReflectionUtils.makeAccessible(constructor);
            return constructor.newInstance(testContext);
        } catch (Exception ex) {
            if (logger.isInfoEnabled()) {
                logger.info(String.format("Failed to invoke copy constructor for [%s]; " + "concurrent test execution is therefore likely not supported.", testContext), ex);
            }
        }
    }
    // Fallback to original instance
    return testContext;
}

19 View Source File : InvocableHandlerMethod.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Invoke the method for the given exchange.
 * @param message the current message
 * @param providedArgs optional list of argument values to match by type
 * @return a Mono with the result from the invocation
 */
@SuppressWarnings("KotlinInternalInJava")
public Mono<Object> invoke(Message<?> message, Object... providedArgs) {
    return getMethodArgumentValues(message, providedArgs).flatMap(args -> {
        Object value;
        try {
            Method method = getBridgedMethod();
            ReflectionUtils.makeAccessible(method);
            if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(method.getDeclaringClreplaced())) {
                value = CoroutinesUtils.invokeHandlerMethod(method, getBean(), args);
            } else {
                value = method.invoke(getBean(), args);
            }
        } catch (IllegalArgumentException ex) {
            replacedertTargetBean(getBridgedMethod(), getBean(), args);
            String text = (ex.getMessage() != null ? ex.getMessage() : "Illegal argument");
            return Mono.error(new IllegalStateException(formatInvokeError(text, args), ex));
        } catch (InvocationTargetException ex) {
            return Mono.error(ex.getTargetException());
        } catch (Throwable ex) {
            // Unlikely to ever get here, but it must be handled...
            return Mono.error(new IllegalStateException(formatInvokeError("Invocation failure", args), ex));
        }
        MethodParameter returnType = getReturnType();
        ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(returnType.getParameterType());
        return (isAsyncVoidReturnType(returnType, adapter) ? Mono.from(adapter.toPublisher(value)) : Mono.justOrEmpty(value));
    });
}

19 View Source File : InvocableHandlerMethod.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Invoke the handler method with the given argument values.
 */
@Nullable
protected Object doInvoke(Object... args) throws Exception {
    ReflectionUtils.makeAccessible(getBridgedMethod());
    try {
        return getBridgedMethod().invoke(getBean(), args);
    } catch (IllegalArgumentException ex) {
        replacedertTargetBean(getBridgedMethod(), getBean(), args);
        String text = (ex.getMessage() != null ? ex.getMessage() : "Illegal argument");
        throw new IllegalStateException(formatInvokeError(text, args), ex);
    } catch (InvocationTargetException ex) {
        // Unwrap for HandlerExceptionResolvers ...
        Throwable targetException = ex.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw (RuntimeException) targetException;
        } else if (targetException instanceof Error) {
            throw (Error) targetException;
        } else if (targetException instanceof Exception) {
            throw (Exception) targetException;
        } else {
            throw new IllegalStateException(formatInvokeError("Invocation failure", args), targetException);
        }
    }
}

19 View Source File : OracleTableMetaDataProvider.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nullable String catalogName, @Nullable String schemaName, @Nullable String tableName) throws SQLException {
    if (!this.includeSynonyms) {
        logger.debug("Defaulting to no synonyms in table meta-data lookup");
        super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName);
        return;
    }
    Connection con = databaseMetaData.getConnection();
    if (con == null) {
        logger.info("Unable to include synonyms in table meta-data lookup - no Connection from DatabaseMetaData");
        super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName);
        return;
    }
    try {
        Clreplaced<?> oracleConClreplaced = con.getClreplaced().getClreplacedLoader().loadClreplaced("oracle.jdbc.OracleConnection");
        con = (Connection) con.unwrap(oracleConClreplaced);
    } catch (ClreplacedNotFoundException | SQLException ex) {
        if (logger.isInfoEnabled()) {
            logger.info("Unable to include synonyms in table meta-data lookup - no Oracle Connection: " + ex);
        }
        super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName);
        return;
    }
    logger.debug("Including synonyms in table meta-data lookup");
    Method setIncludeSynonyms;
    Boolean originalValueForIncludeSynonyms;
    try {
        Method getIncludeSynonyms = con.getClreplaced().getMethod("getIncludeSynonyms");
        ReflectionUtils.makeAccessible(getIncludeSynonyms);
        originalValueForIncludeSynonyms = (Boolean) getIncludeSynonyms.invoke(con);
        setIncludeSynonyms = con.getClreplaced().getMethod("setIncludeSynonyms", boolean.clreplaced);
        ReflectionUtils.makeAccessible(setIncludeSynonyms);
        setIncludeSynonyms.invoke(con, Boolean.TRUE);
    } catch (Throwable ex) {
        throw new InvalidDataAccessApiUsageException("Could not prepare Oracle Connection", ex);
    }
    super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName);
    try {
        setIncludeSynonyms.invoke(con, originalValueForIncludeSynonyms);
    } catch (Throwable ex) {
        throw new InvalidDataAccessApiUsageException("Could not reset Oracle Connection", ex);
    }
}

19 View Source File : ReflectivePropertyAccessor.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Attempt to create an optimized property accessor tailored for a property of a
 * particular name on a particular clreplaced. The general ReflectivePropertyAccessor
 * will always work but is not optimal due to the need to lookup which reflective
 * member (method/field) to use each time read() is called. This method will just
 * return the ReflectivePropertyAccessor instance if it is unable to build a more
 * optimal accessor.
 * <p>Note: An optimal accessor is currently only usable for read attempts.
 * Do not call this method if you need a read-write accessor.
 * @see OptimalPropertyAccessor
 */
public PropertyAccessor createOptimalAccessor(EvaluationContext context, @Nullable Object target, String name) {
    // Don't be clever for arrays or a null target...
    if (target == null) {
        return this;
    }
    Clreplaced<?> clazz = (target instanceof Clreplaced ? (Clreplaced<?>) target : target.getClreplaced());
    if (clazz.isArray()) {
        return this;
    }
    PropertyCacheKey cacheKey = new PropertyCacheKey(clazz, name, target instanceof Clreplaced);
    InvokerPair invocationTarget = this.readerCache.get(cacheKey);
    if (invocationTarget == null || invocationTarget.member instanceof Method) {
        Method method = (Method) (invocationTarget != null ? invocationTarget.member : null);
        if (method == null) {
            method = findGetterForProperty(name, clazz, target);
            if (method != null) {
                invocationTarget = new InvokerPair(method, new TypeDescriptor(new MethodParameter(method, -1)));
                ReflectionUtils.makeAccessible(method);
                this.readerCache.put(cacheKey, invocationTarget);
            }
        }
        if (method != null) {
            return new OptimalPropertyAccessor(invocationTarget);
        }
    }
    if (invocationTarget == null || invocationTarget.member instanceof Field) {
        Field field = (invocationTarget != null ? (Field) invocationTarget.member : null);
        if (field == null) {
            field = findField(name, clazz, target instanceof Clreplaced);
            if (field != null) {
                invocationTarget = new InvokerPair(field, new TypeDescriptor(field));
                ReflectionUtils.makeAccessible(field);
                this.readerCache.put(cacheKey, invocationTarget);
            }
        }
        if (field != null) {
            return new OptimalPropertyAccessor(invocationTarget);
        }
    }
    return this;
}

19 View Source File : ReflectivePropertyAccessor.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) throws AccessException {
    if (!this.allowWrite) {
        throw new AccessException("PropertyAccessor for property '" + name + "' on target [" + target + "] does not allow write operations");
    }
    replacedert.state(target != null, "Target must not be null");
    Clreplaced<?> type = (target instanceof Clreplaced ? (Clreplaced<?>) target : target.getClreplaced());
    Object possiblyConvertedNewValue = newValue;
    TypeDescriptor typeDescriptor = getTypeDescriptor(context, target, name);
    if (typeDescriptor != null) {
        try {
            possiblyConvertedNewValue = context.getTypeConverter().convertValue(newValue, TypeDescriptor.forObject(newValue), typeDescriptor);
        } catch (EvaluationException evaluationException) {
            throw new AccessException("Type conversion failure", evaluationException);
        }
    }
    PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Clreplaced);
    Member cachedMember = this.writerCache.get(cacheKey);
    if (cachedMember == null || cachedMember instanceof Method) {
        Method method = (Method) cachedMember;
        if (method == null) {
            method = findSetterForProperty(name, type, target);
            if (method != null) {
                cachedMember = method;
                this.writerCache.put(cacheKey, cachedMember);
            }
        }
        if (method != null) {
            try {
                ReflectionUtils.makeAccessible(method);
                method.invoke(target, possiblyConvertedNewValue);
                return;
            } catch (Exception ex) {
                throw new AccessException("Unable to access property '" + name + "' through setter method", ex);
            }
        }
    }
    if (cachedMember == null || cachedMember instanceof Field) {
        Field field = (Field) cachedMember;
        if (field == null) {
            field = findField(name, type, target);
            if (field != null) {
                cachedMember = field;
                this.writerCache.put(cacheKey, cachedMember);
            }
        }
        if (field != null) {
            try {
                ReflectionUtils.makeAccessible(field);
                field.set(target, possiblyConvertedNewValue);
                return;
            } catch (Exception ex) {
                throw new AccessException("Unable to access field '" + name + "'", ex);
            }
        }
    }
    throw new AccessException("Neither setter method nor field found for property '" + name + "'");
}

19 View Source File : ReflectivePropertyAccessor.java
License : MIT License
Project Creator : Vip-Augus

@Override
public TypedValue read(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
    replacedert.state(target != null, "Target must not be null");
    Clreplaced<?> type = (target instanceof Clreplaced ? (Clreplaced<?>) target : target.getClreplaced());
    if (type.isArray() && name.equals("length")) {
        if (target instanceof Clreplaced) {
            throw new AccessException("Cannot access length on array clreplaced itself");
        }
        return new TypedValue(Array.getLength(target));
    }
    PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Clreplaced);
    InvokerPair invoker = this.readerCache.get(cacheKey);
    this.lastReadInvokerPair = invoker;
    if (invoker == null || invoker.member instanceof Method) {
        Method method = (Method) (invoker != null ? invoker.member : null);
        if (method == null) {
            method = findGetterForProperty(name, type, target);
            if (method != null) {
                // Treat it like a property...
                // The readerCache will only contain gettable properties (let's not worry about setters for now).
                Property property = new Property(type, method, null);
                TypeDescriptor typeDescriptor = new TypeDescriptor(property);
                invoker = new InvokerPair(method, typeDescriptor);
                this.lastReadInvokerPair = invoker;
                this.readerCache.put(cacheKey, invoker);
            }
        }
        if (method != null) {
            try {
                ReflectionUtils.makeAccessible(method);
                Object value = method.invoke(target);
                return new TypedValue(value, invoker.typeDescriptor.narrow(value));
            } catch (Exception ex) {
                throw new AccessException("Unable to access property '" + name + "' through getter method", ex);
            }
        }
    }
    if (invoker == null || invoker.member instanceof Field) {
        Field field = (Field) (invoker == null ? null : invoker.member);
        if (field == null) {
            field = findField(name, type, target);
            if (field != null) {
                invoker = new InvokerPair(field, new TypeDescriptor(field));
                this.lastReadInvokerPair = invoker;
                this.readerCache.put(cacheKey, invoker);
            }
        }
        if (field != null) {
            try {
                ReflectionUtils.makeAccessible(field);
                Object value = field.get(target);
                return new TypedValue(value, invoker.typeDescriptor.narrow(value));
            } catch (Exception ex) {
                throw new AccessException("Unable to access field '" + name + "'", ex);
            }
        }
    }
    throw new AccessException("Neither getter method nor field found for property '" + name + "'");
}

19 View Source File : ReflectiveMethodExecutor.java
License : MIT License
Project Creator : Vip-Augus

@Override
public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException {
    try {
        this.argumentConversionOccurred = ReflectionHelper.convertArguments(context.getTypeConverter(), arguments, this.originalMethod, this.varargsPosition);
        if (this.originalMethod.isVarArgs()) {
            arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.originalMethod.getParameterTypes(), arguments);
        }
        ReflectionUtils.makeAccessible(this.methodToInvoke);
        Object value = this.methodToInvoke.invoke(target, arguments);
        return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.originalMethod, -1)).narrow(value));
    } catch (Exception ex) {
        throw new AccessException("Problem invoking method: " + this.methodToInvoke, ex);
    }
}

19 View Source File : ReflectiveConstructorExecutor.java
License : MIT License
Project Creator : Vip-Augus

@Override
public TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException {
    try {
        ReflectionHelper.convertArguments(context.getTypeConverter(), arguments, this.ctor, this.varargsPosition);
        if (this.ctor.isVarArgs()) {
            arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.ctor.getParameterTypes(), arguments);
        }
        ReflectionUtils.makeAccessible(this.ctor);
        return new TypedValue(this.ctor.newInstance(arguments));
    } catch (Exception ex) {
        throw new AccessException("Problem invoking constructor: " + this.ctor, ex);
    }
}

19 View Source File : FunctionReference.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Execute a function represented as a {@code java.lang.reflect.Method}.
 * @param state the expression evaluation state
 * @param method the method to invoke
 * @return the return value of the invoked Java method
 * @throws EvaluationException if there is any problem invoking the method
 */
private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException {
    Object[] functionArgs = getArguments(state);
    if (!method.isVarArgs()) {
        int declaredParamCount = method.getParameterCount();
        if (declaredParamCount != functionArgs.length) {
            throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, functionArgs.length, declaredParamCount);
        }
    }
    if (!Modifier.isStatic(method.getModifiers())) {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_MUST_BE_STATIC, ClreplacedUtils.getQualifiedMethodName(method), this.name);
    }
    // Convert arguments if necessary and remap them for varargs if required
    TypeConverter converter = state.getEvaluationContext().getTypeConverter();
    boolean argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method);
    if (method.isVarArgs()) {
        functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(method.getParameterTypes(), functionArgs);
    }
    boolean compilable = false;
    try {
        ReflectionUtils.makeAccessible(method);
        Object result = method.invoke(method.getClreplaced(), functionArgs);
        compilable = !argumentConversionOccurred;
        return new TypedValue(result, new TypeDescriptor(new MethodParameter(method, -1)).narrow(result));
    } catch (Exception ex) {
        throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_FUNCTION_CALL, this.name, ex.getMessage());
    } finally {
        if (compilable) {
            this.exitTypeDescriptor = CodeFlow.toDescriptor(method.getReturnType());
            this.method = method;
        } else {
            this.exitTypeDescriptor = null;
            this.method = null;
        }
    }
}

19 View Source File : ClassloadingAssertions.java
License : MIT License
Project Creator : Vip-Augus

private static boolean isClreplacedLoaded(String clreplacedName) {
    ClreplacedLoader cl = ClreplacedUtils.getDefaultClreplacedLoader();
    Method findLoadedClreplacedMethod = ReflectionUtils.findMethod(cl.getClreplaced(), "findLoadedClreplaced", String.clreplaced);
    ReflectionUtils.makeAccessible(findLoadedClreplacedMethod);
    Clreplaced<?> loadedClreplaced = (Clreplaced<?>) ReflectionUtils.invokeMethod(findLoadedClreplacedMethod, cl, clreplacedName);
    return loadedClreplaced != null;
}

19 View Source File : AbstractRecursiveAnnotationVisitor.java
License : MIT License
Project Creator : Vip-Augus

protected Object getEnumValue(String asmTypeDescriptor, String attributeValue) {
    Object valueToUse = attributeValue;
    try {
        Clreplaced<?> enumType = ClreplacedUtils.forName(Type.getType(asmTypeDescriptor).getClreplacedName(), this.clreplacedLoader);
        Field enumConstant = ReflectionUtils.findField(enumType, attributeValue);
        if (enumConstant != null) {
            ReflectionUtils.makeAccessible(enumConstant);
            valueToUse = enumConstant.get(null);
        }
    } catch (ClreplacedNotFoundException | NoClreplacedDefFoundError ex) {
        logger.debug("Failed to clreplacedload enum type while reading annotation metadata", ex);
    } catch (IllegalAccessException | AccessControlException ex) {
        logger.debug("Could not access enum value while reading annotation metadata", ex);
    }
    return valueToUse;
}

19 View Source File : ObjectToObjectConverter.java
License : MIT License
Project Creator : Vip-Augus

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
    if (source == null) {
        return null;
    }
    Clreplaced<?> sourceClreplaced = sourceType.getType();
    Clreplaced<?> targetClreplaced = targetType.getType();
    Member member = getValidatedMember(targetClreplaced, sourceClreplaced);
    try {
        if (member instanceof Method) {
            Method method = (Method) member;
            ReflectionUtils.makeAccessible(method);
            if (!Modifier.isStatic(method.getModifiers())) {
                return method.invoke(source);
            } else {
                return method.invoke(null, source);
            }
        } else if (member instanceof Constructor) {
            Constructor<?> ctor = (Constructor<?>) member;
            ReflectionUtils.makeAccessible(ctor);
            return ctor.newInstance(source);
        }
    } catch (InvocationTargetException ex) {
        throw new ConversionFailedException(sourceType, targetType, source, ex.getTargetException());
    } catch (Throwable ex) {
        throw new ConversionFailedException(sourceType, targetType, source, ex);
    }
    // If sourceClreplaced is Number and targetClreplaced is Integer, the following message should expand to:
    // No toInteger() method exists on java.lang.Number, and no static valueOf/of/from(java.lang.Number)
    // method or Integer(java.lang.Number) constructor exists on java.lang.Integer.
    throw new IllegalStateException(String.format("No to%3$s() method exists on %1$s, " + "and no static valueOf/of/from(%1$s) method or %3$s(%1$s) constructor exists on %2$s.", sourceClreplaced.getName(), targetClreplaced.getName(), targetClreplaced.getSimpleName()));
}

19 View Source File : ScheduledMethodRunnable.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void run() {
    try {
        ReflectionUtils.makeAccessible(this.method);
        this.method.invoke(this.target);
    } catch (InvocationTargetException ex) {
        ReflectionUtils.rethrowRuntimeException(ex.getTargetException());
    } catch (IllegalAccessException ex) {
        throw new UndeclaredThrowableException(ex);
    }
}

See More Examples