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:com.sm.query.QueryVisitorImpl.java

private Object findId(String id) {
    if (id.toLowerCase().equals(source.getClass().getSimpleName().toLowerCase()))
        return source;
    else {//from w w  w  .  ja v  a  2s .c  o  m
        Pair<Object, FieldInfo> pair = findObjectId(id, source, classInfoMap);
        try {
            if (pair.getFirst() == null)
                return null;
            else
                return pair.getSecond().getField().get(pair.getFirst());
        } catch (IllegalAccessException e) {
            throw new ObjectIdException(e.getMessage(), e);
        }
    }
}

From source file:org.xwiki.velocity.introspection.ChainingUberspector.java

/**
 * Tries to create an uberspector instance using reflection.
 *
 * @param classname The name of the uberspector class to instantiate.
 * @return An instance of the specified Uberspector. If the class cannot be instantiated using the default
 *         constructor, or does not implement {@link Uberspect}, <code>null</code> is returned.
 *//*  www  .  j a  va  2s.co  m*/
protected Uberspect instantiateUberspector(String classname) {
    Object o = null;
    try {
        o = ClassUtils.getNewInstance(classname);
    } catch (ClassNotFoundException cnfe) {
        this.log.warn(String.format("The specified uberspector [%s]"
                + " does not exist or is not accessible to the current classloader.", classname));
    } catch (IllegalAccessException e) {
        this.log.warn(String.format(
                "The specified uberspector [%s] does not have a public default constructor.", classname));
    } catch (InstantiationException e) {
        this.log.warn(String.format("The specified uberspector [%s] cannot be instantiated.", classname));
    } catch (ExceptionInInitializerError e) {
        this.log.warn(String.format("Exception while instantiating the Uberspector [%s]: %s", classname,
                e.getMessage()));
    }

    if (!(o instanceof Uberspect)) {
        if (o != null) {
            this.log.warn("The specified class for Uberspect [" + classname + "] does not implement "
                    + Uberspect.class.getName());
        }
        return null;
    }
    return (Uberspect) o;
}

From source file:velo.entity.EmailTemplate.java

@Deprecated
public Object executeGetMethod(Object obj, String methodName) throws MethodExecutionException {
    //System.out.println("Trying to execute Method name: '" + methodName + "', on Object: " + obj);
    try {/*  ww  w  .  ja va  2s  .c  o m*/
        Class[] parameterTypes = new Class[] {};
        Method name = obj.getClass().getMethod(methodName, parameterTypes);
        Object[] arguments = new Object[] {};
        Object result = name.invoke(obj, arguments);

        return result;

    } catch (InvocationTargetException ite) {
        throw new MethodExecutionException("Could not execute method named: '" + methodName + "' over object: '"
                + obj + "', failed message is: " + ite.getMessage());
    } catch (IllegalAccessException iae) {
        throw new MethodExecutionException("Could not execute method named: '" + methodName + "' over object: '"
                + obj + "', failed message is: " + iae.getMessage());
    } catch (NoSuchMethodException nsme) {
        throw new MethodExecutionException("Could not execute method named: '" + methodName + "' over object: '"
                + obj + "', failed message is: " + nsme.getMessage());
    }
}

From source file:eu.eidas.auth.engine.metadata.MetadataGenerator.java

private Organization buildOrganization() {
    Organization organization = null;/*www .  j a  v  a 2  s.c o m*/
    try {
        organization = BuilderFactoryUtil.buildXmlObject(Organization.class);
        OrganizationDisplayName odn = BuilderFactoryUtil.buildXmlObject(OrganizationDisplayName.class);
        odn.setName(new LocalizedString(params.countryName, MetadataConfigParams.DEFAULT_LANG));
        organization.getDisplayNames().add(odn);
        OrganizationURL url = BuilderFactoryUtil.buildXmlObject(OrganizationURL.class);
        url.setURL(new LocalizedString(params.nodeUrl, MetadataConfigParams.DEFAULT_LANG));
        organization.getURLs().add(url);
    } catch (IllegalAccessException iae) {
        LOGGER.info("ERROR : error generating the Organization: {}", iae.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", iae);
    } catch (NoSuchFieldException nfe) {
        LOGGER.info("ERROR : error generating the Organization: {}", nfe.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", nfe);
    }
    return organization;
}

From source file:com.dungnv.vfw5.base.service.BaseFWServiceImpl.java

@Override
public List prepareCondition(TDTO tForm) {
    List<ConditionBean> lstCondition = new ArrayList<ConditionBean>();
    if (tForm == null) {
        return lstCondition;
    }/*from ww w .  j a  va  2s.com*/
    Method methods[] = tForm.toModel().getClass().getDeclaredMethods();
    Method methodForms[] = tForm.getClass().getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        if (ReflectUtils.isGetter(methods[i])) {
            try {
                Object value = methods[i].invoke(tForm.toModel());
                String returnType = methods[i].getReturnType().getSimpleName().toUpperCase();
                if (value == null || "".equals(value)) {
                    if (ParamUtils.TYPE_NUMBER.indexOf(returnType) >= 0) {
                        try {
                            Column column = methods[i].getAnnotation(Column.class);
                            if (StringUtils.validString(column.columnDefinition())) {
                                String colId = "";
                                String colName = "";
                                for (int j = 0; j < methodForms.length; j++) {
                                    if (methodForms[j].getName().equals(methods[i].getName() + "Name")) {
                                        value = methodForms[j].invoke(tForm);
                                        if (!StringUtils.validString(value)) {
                                            break;
                                        }
                                        Class cl = Class.forName("com.dungnv.ra.database.BO."
                                                + column.columnDefinition() + "BO");
                                        Constructor ct = cl.getConstructor();
                                        Object obj = ct.newInstance();
                                        Method mtd[] = cl.getMethods();
                                        for (int k = 0; k < mtd.length; k++) {
                                            if (mtd[k].getName().equals("getColId")) {
                                                colId = mtd[k].invoke(obj).toString();
                                            }
                                            if (mtd[k].getName().equals("getColName")) {
                                                colName = mtd[k].invoke(obj).toString();
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (StringUtils.validString(value)) {
                                    lstCondition
                                            .add(new ConditionBean(ReflectUtils.getColumnBeanName(methods[i]),
                                                    ParamUtils.OP_IN,
                                                    BaseFWDAOImpl.genSubQuery(column.columnDefinition(), colId,
                                                            colName, value.toString()),
                                                    ParamUtils.TYPE_NUMBER));
                                }
                            }
                        } catch (Exception e) {
                            System.out.println("PrepareCondition Error: " + e.getMessage());
                        }
                    }
                } else if (ParamUtils.TYPE_STRING.indexOf(returnType) >= 0) {
                    if (!value.equals(String.valueOf(ParamUtils.DEFAULT_VALUE))) {
                        String stringValue = value.toString();
                        String opCompare = ParamUtils.OP_LIKE;
                        String valueCompare = StringUtils.formatLike(stringValue);
                        Column column = methods[i].getAnnotation(Column.class);
                        if (StringUtils.validString(column.columnDefinition())
                                && column.columnDefinition().equals("param")) {
                            opCompare = ParamUtils.OP_EQUAL;
                            valueCompare = stringValue.toLowerCase(Locale.ENGLISH);
                        }
                        if (!stringValue.trim().equals("")) {
                            lstCondition.add(new ConditionBean(
                                    StringUtils.formatFunction("lower",
                                            ReflectUtils.getColumnBeanName(methods[i])),
                                    opCompare, valueCompare, ParamUtils.TYPE_STRING));
                        }
                    }
                } else if (ParamUtils.TYPE_NUMBER.indexOf(returnType) >= 0) {
                    if (!value.toString().equals(String.valueOf(ParamUtils.DEFAULT_VALUE))) {
                        lstCondition.add(new ConditionBean(ReflectUtils.getColumnBeanName(methods[i]),
                                ParamUtils.OP_EQUAL, value.toString(), ParamUtils.TYPE_NUMBER));
                    }
                } else if (ParamUtils.TYPE_DATE.indexOf(returnType) >= 0) {
                    Date dateValue = (Date) value;
                    String methodName = methods[i].getName();
                    String operator = ParamUtils.OP_EQUAL;
                    if (methodName.indexOf("From") >= 0 || methodName.indexOf("Begin") >= 0
                            || methodName.indexOf("Sta") >= 0) {
                        operator = ParamUtils.OP_GREATER_EQUAL;
                    } else if (methodName.indexOf("To") >= 0 || methodName.indexOf("End") >= 0
                            || methodName.indexOf("Last") >= 0) {
                        operator = ParamUtils.OP_LESS_EQUAL;
                    }
                    lstCondition.add(new ConditionBean(
                            StringUtils.formatFunction("trunc", ReflectUtils.getColumnBeanName(methods[i])),
                            operator, StringUtils.formatDate(dateValue), ParamUtils.TYPE_DATE));
                }
            } catch (IllegalAccessException iae) {
                System.out.println("PrepareCondition Error: " + iae.getMessage());
            } catch (InvocationTargetException ite) {
                System.out.println("PrepareCondition Error: " + ite.getMessage());
            }
        }
    }
    return lstCondition;
}

From source file:org.kuali.coeus.common.budget.framework.query.QueryList.java

/** calculates the sum of the field in this QueryList.
 * @param fieldName field of bean whose sum has to be calculated.
 * @param arg argument for the getter method of field if it takes any argumnt,
 * else can be null.//from ww  w. ja  v a2s  . c o m
 * @param value value for the argument, else can be null.
 * @return returns sum.
 */
public double sum(String fieldName, Class arg, Object value) {
    if (size() == 0) {
        return 0;
    }

    Object current;
    Field field = null;
    Method method = null;
    Class dataClass = get(0).getClass();
    double sum = 0;

    try {
        field = dataClass.getDeclaredField(fieldName);

        Class fieldClass = field.getType();
        if (!(fieldClass.equals(Integer.class) || fieldClass.equals(Long.class)
                || fieldClass.equals(Double.class) || fieldClass.equals(Float.class)
                || fieldClass.equals(BigDecimal.class) || fieldClass.equals(BigInteger.class)
                || fieldClass.equals(ScaleTwoDecimal.class) || fieldClass.equals(ScaleTwoDecimal.class)
                || fieldClass.equals(int.class) || fieldClass.equals(long.class)
                || fieldClass.equals(float.class) || fieldClass.equals(double.class))) {
            throw new UnsupportedOperationException("Data Type not numeric");
        }

        if (!field.isAccessible()) {
            throw new NoSuchFieldException();
        }
    } catch (NoSuchFieldException noSuchFieldException) {
        try {
            String methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
            if (arg != null) {
                Class args[] = { arg };
                method = dataClass.getMethod(methodName, args);
            } else {
                method = dataClass.getMethod(methodName, null);
            }
        } catch (NoSuchMethodException noSuchMethodException) {
            LOG.error(noSuchMethodException.getMessage(), noSuchMethodException);
        }
    }

    for (int index = 0; index < size(); index++) {
        current = get(index);

        try {
            if (field != null && field.isAccessible()) {
                sum = sum + Double.parseDouble(((Comparable) field.get(current)).toString());
            } else {
                Comparable dataValue;
                if (value != null) {
                    Object values[] = { value };
                    dataValue = (Comparable) method.invoke(current, values);
                } else {
                    dataValue = (Comparable) method.invoke(current, null);
                }
                if (dataValue != null) {
                    sum += Double.parseDouble(dataValue.toString());
                }

            }
        } catch (IllegalAccessException illegalAccessException) {
            LOG.error(illegalAccessException.getMessage(), illegalAccessException);
        } catch (InvocationTargetException invocationTargetException) {
            LOG.error(invocationTargetException.getMessage(), invocationTargetException);
        }
    }
    return sum;
}

From source file:eu.eidas.auth.engine.metadata.MetadataGenerator.java

private ContactPerson buildContact(ContactPersonTypeEnumeration contactType) {
    ContactPerson contact = null;//from  w  w w.  j av  a 2 s .co  m
    try {
        Contact currentContact = null;
        if (contactType == ContactPersonTypeEnumeration.SUPPORT) {
            currentContact = params.getSupportContact();
        } else if (contactType == ContactPersonTypeEnumeration.TECHNICAL) {
            currentContact = params.getTechnicalContact();
        } else {
            LOGGER.error("ERROR: unsupported contact type");
        }
        contact = BuilderFactoryUtil.buildXmlObject(ContactPerson.class);
        if (currentContact == null) {
            LOGGER.error("ERROR: cannot retrieve contact from the configuration");
            return contact;
        }

        EmailAddress emailAddressObj = BuilderFactoryUtil.buildXmlObject(EmailAddress.class);
        Company company = BuilderFactoryUtil.buildXmlObject(Company.class);
        GivenName givenName = BuilderFactoryUtil.buildXmlObject(GivenName.class);
        SurName surName = BuilderFactoryUtil.buildXmlObject(SurName.class);
        TelephoneNumber phoneNumber = BuilderFactoryUtil.buildXmlObject(TelephoneNumber.class);
        contact.setType(contactType);
        emailAddressObj.setAddress(currentContact.getEmail());
        company.setName(currentContact.getCompany());
        givenName.setName(currentContact.getGivenName());
        surName.setName(currentContact.getSurName());
        phoneNumber.setNumber(currentContact.getPhone());

        populateContact(contact, currentContact, emailAddressObj, company, givenName, surName, phoneNumber);

    } catch (IllegalAccessException iae) {
        LOGGER.info("ERROR : error generating the Organization: {}", iae.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", iae);
    } catch (NoSuchFieldException nfe) {
        LOGGER.info("ERROR : error generating the Organization: {}", nfe.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", nfe);
    }
    return contact;
}

From source file:org.projectforge.database.XmlDump.java

/**
 * @param o1//from w  ww.  j a va  2  s . co m
 * @param o2
 * @param logDifference If true than the difference is logged.
 * @return True if the given objects are equal.
 */
private boolean equals(final Object o1, final Object o2, final boolean logDifference) {
    if (o1 == null) {
        final boolean equals = (o2 == null);
        if (equals == false && logDifference == true) {
            log.error("Value 1 is null and value 2 is " + o2);
        }
        return equals;
    } else if (o2 == null) {
        if (logDifference == true) {
            log.error("Value 2 is null and value 1 is " + o1);
        }
        return false;
    }
    final Class<?> cls1 = o1.getClass();
    final Field[] fields = cls1.getDeclaredFields();
    AccessibleObject.setAccessible(fields, true);
    for (final Field field : fields) {
        if (accept(field) == false) {
            continue;
        }
        try {
            final Object fieldValue1 = getValue(o1, o2, field);
            final Object fieldValue2 = getValue(o2, o1, field);
            if (field.getType().isPrimitive() == true) {
                if (ObjectUtils.equals(fieldValue2, fieldValue1) == false) {
                    if (logDifference == true) {
                        log.error("Field '" + field.getName() + "': value 1 '" + fieldValue1
                                + "' is different from value 2 '" + fieldValue2 + "'.");
                    }
                    return false;
                }
                continue;
            } else if (fieldValue1 == null) {
                if (fieldValue2 != null) {
                    if (logDifference == true) {
                        log.error("Field '" + field.getName() + "': value 1 '" + fieldValue1
                                + "' is different from value 2 '" + fieldValue2 + "'.");
                    }
                    return false;
                }
            } else if (fieldValue2 == null) {
                if (fieldValue1 != null) {
                    if (logDifference == true) {
                        log.error("Field '" + field.getName() + "': value 1 '" + fieldValue1
                                + "' is different from value 2 '" + fieldValue2 + "'.");
                    }
                    return false;
                }
            } else if (fieldValue1 instanceof Collection<?>) {
                final Collection<?> col1 = (Collection<?>) fieldValue1;
                final Collection<?> col2 = (Collection<?>) fieldValue2;
                if (col1.size() != col2.size()) {
                    if (logDifference == true) {
                        log.error("Field '" + field.getName() + "': colection's size '" + col1.size()
                                + "' is different from collection's size '" + col2.size() + "'.");
                    }
                    return false;
                }
                if (equals(field, col1, col2, logDifference) == false
                        || equals(field, col2, col1, logDifference) == false) {
                    return false;
                }
            } else if (HibernateUtils.isEntity(fieldValue1.getClass()) == true) {
                if (fieldValue2 == null || ObjectUtils.equals(HibernateUtils.getIdentifier(fieldValue1),
                        HibernateUtils.getIdentifier(fieldValue2)) == false) {
                    if (logDifference == true) {
                        log.error("Field '" + field.getName() + "': Hibernate object id '"
                                + HibernateUtils.getIdentifier(fieldValue1) + "' is different from id '"
                                + HibernateUtils.getIdentifier(fieldValue2) + "'.");
                    }
                    return false;
                }
            } else if (fieldValue1 instanceof BigDecimal) {
                if (fieldValue2 == null
                        || ((BigDecimal) fieldValue1).compareTo((BigDecimal) fieldValue2) != 0) {
                    if (logDifference == true) {
                        log.error("Field '" + field.getName() + "': value 1 '" + fieldValue1
                                + "' is different from value 2 '" + fieldValue2 + "'.");
                    }
                    return false;
                }
            } else if (ObjectUtils.equals(fieldValue2, fieldValue1) == false) {
                if (logDifference == true) {
                    log.error("Field '" + field.getName() + "': value 1 '" + fieldValue1
                            + "' is different from value 2 '" + fieldValue2 + "'.");
                }
                return false;
            }
        } catch (final IllegalAccessException ex) {
            throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage());
        }
    }
    return true;
}

From source file:com.netflix.spinnaker.halyard.config.model.v1.node.Node.java

public List<String> backupLocalFiles(String outputPath) {
    List<String> files = new ArrayList<>();

    Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> {
        try {/* ww w  .j  ava 2 s  .c  om*/
            f.setAccessible(true);
            String fPath = (String) f.get(n);
            if (fPath == null) {
                try {
                    fPath = (String) n.getClass().getMethod("get" + StringUtils.capitalize(f.getName()))
                            .invoke(n);
                } catch (NoSuchMethodException | InvocationTargetException ignored) {
                }
            }

            if (fPath == null) {
                return null;
            }

            File fFile = new File(fPath);
            String fName = fFile.getName();

            // Hash the path to uniquely flatten all files into the output directory
            Path newName = Paths.get(outputPath, Math.abs(fPath.hashCode()) + "-" + fName);
            File parent = newName.toFile().getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            } else if (fFile.getParent().equals(parent.toString())) {
                // Don't move paths that are already in the right folder
                return fPath;
            }
            Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING);

            f.set(n, newName.toString());
            return newName.toString();
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e);
        } catch (IOException e) {
            throw new HalException(FATAL, "Failed to backup user file: " + e.getMessage(), e);
        } finally {
            f.setAccessible(false);
        }
    }).filter(Objects::nonNull).collect(Collectors.toList()));
    recursiveConsume(fileFinder);

    return files;
}

From source file:com.sm.query.QueryVisitorImpl.java

/**
 * treat String as non primitive//from w  ww.j  av  a2s. c o m
 * @param from
 * @param list
 * @return target object let populate only in field list
 */
private void trim(Object from, List<String> list, String prefix) {
    ClassInfo classInfo = findClassInfo(from, classInfoMap);
    for (FieldInfo each : classInfo.getFieldInfos()) {
        int rs = inList(prefix + each.getField().getName(), list);
        if (rs == 0) { //no match and not primitive
            if (!isPrimitive(each.getType())) {
                try {
                    each.getField().set(from, null);
                } catch (IllegalAccessException e) {
                    //swallow exception
                    logger.error(e.getMessage());
                }
            }
        } else if (rs == 2) { //match but it is object with field
            try {
                Object obj = each.getField().get(from);
                if (obj != null) { //it is object that has field in the list
                    //with prefix of simple name +"."
                    trim(obj, list, obj.getClass().getSimpleName() + ".");
                }
            } catch (IllegalAccessException e) {
                //swallow exception
                logger.error(e.getMessage());
            }

        } else if (rs == 1)
            ;
        // match  do nothing
        else {
            logger.warn("wrong inList " + rs + " for " + each.getField().getName());
        }
    }
}