Example usage for java.lang IllegalAccessException getMessage

List of usage examples for java.lang IllegalAccessException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalAccessException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.openspaces.pu.container.ProcessingUnitContainerContextBeanPostProcessor.java

private static Metric getMetricFromMethod(final Method method, final Object bean) {
    if (method.getParameterTypes().length != 0) {
        if (logger.isWarnEnabled())
            logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName()
                    + " is skipped - metric method cannot have parameters");
        return null;
    }/*from   w w  w  .  j a  v  a 2 s .  c  om*/
    if (method.getReturnType().equals(Void.TYPE)) {
        if (logger.isWarnEnabled())
            logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName()
                    + " is skipped - metric method cannot return void");
        return null;
    }

    if (Modifier.isStatic(method.getModifiers())) {
        if (logger.isWarnEnabled())
            logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName()
                    + " is skipped - metric method cannot be static");
        return null;
    }

    if (!method.isAccessible())
        method.setAccessible(true);

    if (Metric.class.isAssignableFrom(method.getReturnType())) {
        try {
            return (Metric) method.invoke(bean);
        } catch (IllegalAccessException e) {
            if (logger.isWarnEnabled())
                logger.warn("Metric registration of method " + method.getName() + " in "
                        + bean.getClass().getName() + " is skipped - failed to get metric - " + e.getMessage());
            return null;
        } catch (InvocationTargetException e) {
            if (logger.isWarnEnabled())
                logger.warn("Metric registration of method " + method.getName() + " in "
                        + bean.getClass().getName() + " is skipped - failed to get metric - " + e.getMessage());
            return null;
        }
    }

    return new Gauge<Object>() {
        @Override
        public Object getValue() throws Exception {
            return method.invoke(bean);
        }
    };
}

From source file:hm.binkley.util.XPropsConverter.java

@SuppressWarnings("unchecked")
private static <T, E extends Exception> Conversion<T, E> invokeValueOf(final Class<T> token)
        throws NoSuchMethodError {
    try {//from w  w  w .j a v  a 2  s .co  m
        final Method method = token.getMethod("valueOf", String.class);
        return value -> {
            try {
                return (T) method.invoke(null, value);
            } catch (final IllegalAccessException e) {
                final IllegalAccessError x = new IllegalAccessError(e.getMessage());
                x.setStackTrace(e.getStackTrace());
                throw x;
            } catch (final InvocationTargetException e) {
                final Throwable root = getRootCause(e);
                final RuntimeException x = new RuntimeException(root);
                x.setStackTrace(root.getStackTrace());
                throw x;
            }
        };
    } catch (final NoSuchMethodException ignored) {
        return null;
    }
}

From source file:hm.binkley.util.XPropsConverter.java

@SuppressWarnings("unchecked")
private static <T, E extends Exception> Conversion<T, E> invokeOf(final Class<T> token)
        throws NoSuchMethodError {
    try {//from   w w w  .j a  v  a  2 s . c o  m
        final Method method = token.getMethod("of", String.class);
        return value -> {
            try {
                return (T) method.invoke(null, value);
            } catch (final IllegalAccessException e) {
                final IllegalAccessError x = new IllegalAccessError(e.getMessage());
                x.setStackTrace(e.getStackTrace());
                throw x;
            } catch (final InvocationTargetException e) {
                final Throwable root = getRootCause(e);
                final RuntimeException x = new RuntimeException(root);
                x.setStackTrace(root.getStackTrace());
                throw x;
            }
        };
    } catch (final NoSuchMethodException ignored) {
        return null;
    }
}

From source file:com.rapid.develop.core.utils.ReflectionUtils.java

/**
 * , private/protected, ??setter./*from  ww w .  jav a2s  .  c  o  m*/
 */
public static void setFieldValue(final Object obj, final String fieldName, final Object value) {
    Field field = getAccessibleField(obj, fieldName);

    if (field == null) {
        throw new IllegalArgumentException("Could not find fields [" + fieldName + "] on target [" + obj + "]");
    }

    try {
        field.set(obj, value);
    } catch (IllegalAccessException e) {
        logger.error("??:{}", e.getMessage());
    }
}

From source file:hm.binkley.util.XPropsConverter.java

private static <T, E extends Exception> Conversion<T, E> invokeConstructor(final Class<T> token)
        throws NoSuchMethodError {
    try {/*from  www . java2  s . co  m*/
        final Constructor<T> ctor = token.getConstructor(String.class);
        return value -> {
            try {
                return ctor.newInstance(value);
            } catch (final IllegalAccessException e) {
                final IllegalAccessError x = new IllegalAccessError(e.getMessage());
                x.setStackTrace(e.getStackTrace());
                throw x;
            } catch (final InvocationTargetException e) {
                final Throwable root = getRootCause(e);
                final RuntimeException x = new RuntimeException(root);
                x.setStackTrace(root.getStackTrace());
                throw x;
            } catch (final InstantiationException e) {
                final InstantiationError x = new InstantiationError(e.getMessage());
                x.setStackTrace(e.getStackTrace());
                throw x;
            }
        };
    } catch (final NoSuchMethodException ignored) {
        return null;
    }
}

From source file:com.rapid.develop.core.utils.ReflectionUtils.java

/**
 * ?, private/protected, ??getter.//from   w w  w.ja va2s.  co m
 */
public static Object getFieldValue(final Object obj, final String fieldName) {
    Field field = getAccessibleField(obj, fieldName);

    if (field == null) {
        throw new IllegalArgumentException("Could not find fields [" + fieldName + "] on target [" + obj + "]");
    }

    Object result = null;
    try {
        result = field.get(obj);
    } catch (IllegalAccessException e) {
        logger.error("??{}", e.getMessage());
    }
    return result;
}

From source file:info.donsun.core.utils.Reflections.java

/**
 * , private/protected, ??setter.//from  w  ww . j a va2s .c om
 */
public static void setFieldValue(final Object obj, final String fieldName, final Object value) {
    Field field = getAccessibleField(obj, fieldName);

    if (field == null) {
        throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]");
    }

    try {
        field.set(obj, value);
    } catch (IllegalAccessException e) {
        logger.error("setFieldValue:{}", e.getMessage());
    }
}

From source file:com.project.framework.util.ReflectionUtils.java

/**
 * , private/protected, ??setter.//w ww  .  java 2  s  .  co  m
 */
public static void setFieldValue(final Object object, final String fieldName, final Object value) {

    Field field = getDeclaredField(object, fieldName);

    Assert.notNull(field, "Could not find field [" + fieldName + "] on target [" + object + "]");

    makeAccessible(field);

    try {
        field.set(object, value);
    } catch (IllegalAccessException e) {
        logger.error("??:{}", e.getMessage());
    }
}

From source file:info.donsun.core.utils.Reflections.java

/**
 * , private/protected, ??setter./*from   www  .  ja va2  s  .com*/
 */
public static void setFieldValue(final Class<?> clazz, final String fieldName, final Object value) {
    Field field = getAccessibleField(clazz, fieldName);

    if (field == null) {
        throw new IllegalArgumentException(
                "Could not find field [" + fieldName + "] on target [" + clazz + "]");
    }

    try {
        field.set(clazz, value);
    } catch (IllegalAccessException e) {
        logger.error("setFieldValue:{}", e.getMessage());
    }
}

From source file:com.project.framework.util.ReflectionUtils.java

/**
 * ?, private/protected, ??getter./*from   ww  w  . jav a  2 s  . com*/
 */
public static Object getFieldValue(final Object object, final String fieldName) {

    Field field = getDeclaredField(object, fieldName);

    Assert.notNull(field, "Could not find field [" + fieldName + "] on target [" + object + "]");

    makeAccessible(field);

    Object result = null;
    try {
        result = field.get(object);
    } catch (IllegalAccessException e) {
        logger.error("??{}", e.getMessage());
    }
    return result;
}