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.zaizi.sensefy.api.utils.SensefyUserMapper.java

@SuppressWarnings("unchecked")
public static SensefyUser getSensefyUserFromPrincipal(Principal user) {

    SensefyUser sensefyUser = new SensefyUser();

    if (user != null) {
        OAuth2Authentication authUser = (OAuth2Authentication) user;
        if (authUser != null) {

            LinkedHashMap<String, Object> details = (LinkedHashMap<String, Object>) authUser
                    .getUserAuthentication().getDetails();

            if (details != null && !details.isEmpty() && details.containsKey("principal")) {
                LinkedHashMap<String, Object> principal = (LinkedHashMap<String, Object>) details
                        .get("principal");

                if (principal != null && !principal.isEmpty()) {
                    try {
                        BeanUtils.populate(sensefyUser, principal);
                    } catch (IllegalAccessException e) {
                        logger.debug(e.getMessage());
                    } catch (InvocationTargetException e) {
                        logger.debug(e.getMessage());
                    }/*from w  w w.  j av  a2  s. c  om*/
                }

            }

        }

    }
    return sensefyUser;
}

From source file:Main.java

public static int getIntField(Object obj, String fieldName) {
    try {//from  w  w  w.j  a v a 2s .c om
        return findField(obj.getClass(), fieldName).getInt(obj);
    } catch (IllegalAccessException e) {
        // should not happen
        //XposedBridge.log(e);
        Log.v("test", e.getMessage());
        throw new IllegalAccessError(e.getMessage());
    } catch (IllegalArgumentException e) {
        throw e;
    }
}

From source file:Main.java

public static String[] getClassStaticFieldNames(Class c, Type fieldType, String nameContains) {
    Field[] fields = c.getDeclaredFields();
    List<String> list = new ArrayList<>();
    for (Field field : fields) {
        try {//from   w ww . j a  va 2  s.com
            boolean isString = field.getType().equals(fieldType);
            boolean containsExtra = field.getName().contains(nameContains);
            boolean isStatic = Modifier.isStatic(field.getModifiers());
            if (field.getType().equals(String.class) && field.getName().contains("EXTRA_")
                    && Modifier.isStatic(field.getModifiers()))
                list.add(String.valueOf(field.get(null)));
        } catch (IllegalAccessException iae) {
            Log.d(TAG,
                    "!!!!!!!!!!!! class Static field, illegal access exception message: " + iae.getMessage());
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:no.abmu.util.reflection.FieldUtil.java

public static Object getFieldValue(Object obj, String fieldName) {
    Assert.checkRequiredArgument("obj", obj);
    Assert.checkRequiredArgument("fieldName", fieldName);
    String errorMessage = "Object '" + obj.getClass().getName() + " does not have field/variable with name '"
            + fieldName + "'";
    Assert.assertTrue(errorMessage, hasObjectVariable(obj, fieldName));

    Field field = getField(obj, fieldName);

    Object value = null;/*  ww  w .  j a  v a2s . c om*/
    try {
        if (Modifier.isPublic(field.getModifiers())) {
            value = field.get(obj);
        } else {
            field.setAccessible(true);
            value = field.get(obj);
            field.setAccessible(false);
        }
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
    }

    return value;
}

From source file:no.abmu.util.reflection.FieldUtil.java

public static boolean setFieldValue(Object obj, String fieldName, Object value) {
    Assert.checkRequiredArgument("obj", obj);
    Assert.checkRequiredArgument("fieldName", fieldName);
    String errorMessage = "Object '" + obj.getClass().getName() + " does not have field/variable with name '"
            + fieldName + "'";
    Assert.assertTrue(errorMessage, hasObjectVariable(obj, fieldName));

    Field field = getField(obj, fieldName);

    boolean sucess = false;
    try {/*w  w  w.j av  a  2s .c  om*/
        if (Modifier.isPublic(field.getModifiers())) {
            field.set(obj, value);
        } else {
            field.setAccessible(true);
            field.set(obj, value);
            field.setAccessible(false);
        }
        sucess = true;
    } catch (IllegalAccessException e) {
        logger.warn(e.getMessage());
    }

    return sucess;
}

From source file:ml.dmlc.xgboost4j.java.NativeLibLoader.java

/**
 * Add libPath to java.library.path, then native library in libPath would be load properly
 *
 * @param libPath library path/*from   ww  w.  ja  v a  2 s . c o  m*/
 * @throws IOException exception
 */
private static void addNativeDir(String libPath) throws IOException {
    try {
        Field field = ClassLoader.class.getDeclaredField("usr_paths");
        field.setAccessible(true);
        String[] paths = (String[]) field.get(null);
        for (String path : paths) {
            if (libPath.equals(path)) {
                return;
            }
        }
        String[] tmp = new String[paths.length + 1];
        System.arraycopy(paths, 0, tmp, 0, paths.length);
        tmp[paths.length] = libPath;
        field.set(null, tmp);
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
        throw new IOException("Failed to get permissions to set library path");
    } catch (NoSuchFieldException e) {
        logger.error(e.getMessage());
        throw new IOException("Failed to get field handle to set library path");
    }
}

From source file:hivemall.xgboost.NativeLibLoader.java

/**
 * Add libPath to java.library.path, then native library in libPath would be load properly.
 *
 * @param libPath library path// www. j  a  v a  2 s.c  o  m
 * @throws IOException exception
 */
private static void addLibraryPath(String libPath) throws IOException {
    try {
        final Field field = ClassLoader.class.getDeclaredField("usr_paths");
        field.setAccessible(true);
        final String[] paths = (String[]) field.get(null);
        for (String path : paths) {
            if (libPath.equals(path)) {
                return;
            }
        }
        final String[] tmp = new String[paths.length + 1];
        System.arraycopy(paths, 0, tmp, 0, paths.length);
        tmp[paths.length] = libPath;
        field.set(null, tmp);
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
        throw new IOException("Failed to get permissions to set library path");
    } catch (NoSuchFieldException e) {
        logger.error(e.getMessage());
        throw new IOException("Failed to get field handle to set library path");
    }
}

From source file:com.tacitknowledge.util.migration.jdbc.util.SqlUtil.java

/**
 * Established and returns a connection based on the specified parameters.
 *
 * @param driver the JDBC driver to use//from w w w  .j a  v  a  2s .  com
 * @param url    the database URL
 * @param user   the username
 * @param pass   the password
 * @return a JDBC connection
 * @throws ClassNotFoundException if the driver could not be loaded
 * @throws SQLException           if a connnection could not be made to the database
 */
public static Connection getConnection(String driver, String url, String user, String pass)
        throws ClassNotFoundException, SQLException {
    Connection conn = null;
    try {
        Class.forName(driver);
        log.debug("Getting Connection to " + url);
        conn = DriverManager.getConnection(url, user, pass);
    } catch (Exception e) {
        /* work around for DriverManager 'feature'.  
         * In some cases, the jdbc driver jar is injected into a new 
         * child classloader (for example, maven provides different 
         * class loaders for different build lifecycle phases). 
         * 
         * Since DriverManager uses the calling class' loader instead 
         * of the current context's loader, it fails to find the driver.
         * 
         * Our work around is to give the current context's class loader 
         * a shot at finding the driver in cases where DriverManager fails.  
         * This 'may be' a security hole which is why DriverManager implements 
         * things in such a way that it doesn't use the current thread context class loader.
         */
        try {
            Class driverClass = Class.forName(driver, true, Thread.currentThread().getContextClassLoader());
            Driver driverImpl = (Driver) driverClass.newInstance();
            Properties props = new Properties();
            props.put("user", user);
            props.put("password", pass);
            conn = driverImpl.connect(url, props);
        } catch (InstantiationException ie) {
            log.debug(ie);
            throw new SQLException(ie.getMessage());
        } catch (IllegalAccessException iae) {
            log.debug(iae);
            throw new SQLException(iae.getMessage());
        }
    }

    return conn;
}

From source file:fr.paris.lutece.plugins.crm.util.ListUtils.java

/**
 *
 * Transforms a basical list to a reference list
 * @param list//  w w w  .j  a va 2  s . co  m
 * @param key
 * @param value
 * @param firstItem
 * @return a reference list
 */
public static ReferenceList toReferenceList(List<?> list, String key, String value, String firstItem) {
    ReferenceList referenceList = new ReferenceList();
    String valeurKey;
    String valeurValue;

    try {
        if (firstItem != null) {
            referenceList.addItem("-1", firstItem);
        }

        for (Object element : list) {
            valeurKey = BeanUtils.getSimpleProperty(element, key);
            valeurValue = BeanUtils.getSimpleProperty(element, value);
            referenceList.addItem(valeurKey, valeurValue);
        }
    } catch (IllegalAccessException e) {
        LOGGER.warn("Erreur lors de la cration d'une liste pour combo : " + e.getMessage(), e);
    } catch (InvocationTargetException e) {
        LOGGER.warn("Erreur lors de la cration d'une liste pour combo : " + e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        LOGGER.warn("Erreur lors de la cration d'une liste pour combo : " + e.getMessage(), e);
    } catch (Exception e) {
        LOGGER.warn("Erreur lors de la cration d'une liste pour combo : " + e.getMessage(), e);
    }

    return referenceList;
}

From source file:com.iflytek.edu.cloud.frame.utils.ReflectionUtils.java

/**
 * ,private/protected,??setter.//from w  ww.j  a v  a  2 s  .com
 */
public static void setFieldValue(final Object object, final String fieldName, final Object value) {
    Field field = getDeclaredField(object, fieldName);

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

    makeAccessible(field);

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