Example usage for java.lang IllegalAccessException getCause

List of usage examples for java.lang IllegalAccessException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.bitranger.parknshop.common.recommend.collections.CollectionUtils.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <E> Iterable<E> fast(final Iterable<E> iter) {
    if (iter instanceof FastIterable) {
        return new Iterable<E>() {
            @Override//  w  w w.ja va  2 s  .  co m
            public Iterator<E> iterator() {
                return ((FastIterable) iter).fastIterator();
            }
        };
    } else if (iter instanceof Cursor) {
        throw new IllegalArgumentException();
    } else {
        Optional<Method> fastMethod = fastIteratorMethods.getUnchecked(iter.getClass());
        if (fastMethod.isPresent()) {
            final Method method = fastMethod.get();
            return new Iterable<E>() {
                @Override
                public Iterator<E> iterator() {
                    try {
                        return (Iterator<E>) method.invoke(iter);
                    } catch (IllegalAccessException e) {
                        return iter.iterator();
                    } catch (InvocationTargetException e) {
                        throw Throwables.propagate(e.getCause());
                    }
                }
            };
        } else {
            return iter;
        }
    }
}

From source file:com.amazonaws.http.HttpRequestTimer.java

/**
 * {@link ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy(boolean)} is not available in Java
 * 6 so we invoke it with reflection to be able to compile against Java 6.
 * /*from ww w. ja va  2  s  .c om*/
 * @param executor
 */
private static void safeSetRemoveOnCancel(ScheduledThreadPoolExecutor executor) {
    try {
        executor.getClass().getMethod("setRemoveOnCancelPolicy", boolean.class).invoke(executor, Boolean.TRUE);
    } catch (IllegalAccessException e) {
        throwSetRemoveOnCancelException(e);
    } catch (IllegalArgumentException e) {
        throwSetRemoveOnCancelException(e);
    } catch (InvocationTargetException e) {
        throwSetRemoveOnCancelException(e.getCause());
    } catch (NoSuchMethodException e) {
        throw new AmazonClientException(
                "The request timeout feature is only available for Java 1.7 and above.");
    } catch (SecurityException e) {
        throw new AmazonClientException("The request timeout feature needs additional permissions to function.",
                e);
    }
}

From source file:org.grouplens.lenskit.collections.CollectionUtils.java

/**
 * Use the fast iterator of an iterable, if available.
 *
 * @param <E>  The type of object to iterate.
 * @param iter An iterable to wrap/*  w ww .  j a v  a  2  s  . c  o m*/
 * @return An iterable using the underlying iterable's fast iterator, if present,
 *         to do iteration. Fast iteration is detected by looking for a {@code fastIterator()}
 *         method, like is present in {@link FastEntrySet}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <E> Iterable<E> fast(final Iterable<E> iter) {
    if (iter instanceof FastIterable) {
        return new Iterable<E>() {
            @Override
            public Iterator<E> iterator() {
                return ((FastIterable) iter).fastIterator();
            }
        };
    } else if (iter instanceof Cursor) {
        return ((Cursor<E>) iter).fast();
    } else {
        Optional<Method> fastMethod = fastIteratorMethods.getUnchecked(iter.getClass());
        if (fastMethod.isPresent()) {
            final Method method = fastMethod.get();
            return new Iterable<E>() {
                @Override
                public Iterator<E> iterator() {
                    try {
                        return (Iterator<E>) method.invoke(iter);
                    } catch (IllegalAccessException e) {
                        return iter.iterator();
                    } catch (InvocationTargetException e) {
                        throw Throwables.propagate(e.getCause());
                    }
                }
            };
        } else {
            return iter;
        }
    }
}

From source file:org.nuclos.common.collect.collectable.AbstractCollectableBean.java

/**
 * Utility method to set a bean property.
 * @param sPropertyName/*from  w w w .j  a  v a2 s  . com*/
 * @param oValue
 * @todo Replace with CollectableElisaValueObject.setPropertyValue implementation and move to BeanUtils.
 */
protected static void setProperty(Object oBean, String sPropertyName, Object oValue)
        throws NoSuchMethodException {
    try {
        PropertyUtils.setSimpleProperty(oBean, sPropertyName, oValue);
        /** @todo BeanUtils.setProperty(tBean, sPropertyName, oValue); */
    } catch (IllegalAccessException ex) {
        throw new CommonFatalException(getErrorMessage(sPropertyName, oBean, true), ex);
    } catch (InvocationTargetException ex) {
        throw new CommonFatalException(getErrorMessage(sPropertyName, oBean, true), ex.getCause());
    } catch (IllegalArgumentException ex) {
        throw new CommonFatalException(getErrorMessage(sPropertyName, oBean, true), ex);
    }
}

From source file:au.com.cybersearch2.classyjpa.entity.ObjectMonitor.java

/**
 * Merge entity objects. Performs copy using reflection.
 * @param dest Entity to be updated/*w ww. j  a v  a  2  s .co  m*/
 * @param orig Source entity
 */
private static <T> void mergeObjects(T dest, T orig) {
    try {
        PropertyUtils.copyProperties(dest, orig);
    } catch (IllegalAccessException e) {
        throw createReflectionErrorException("refresh", e.toString());
    } catch (InvocationTargetException e) {
        throw createReflectionErrorException("refresh",
                e.getCause() == null ? e.toString() : e.getCause().toString());
    } catch (NoSuchMethodException e) {
        throw createReflectionErrorException("refresh", e.toString());
    }
}

From source file:org.kuali.rice.kew.api.WorkflowDocumentFactory.java

/**
 * Loads an existing workflow document./*  ww  w. j a v  a2s .  c  o  m*/
 * @param principalId the principal id under which to perform document actions
 * @param documentId the id of the document to load
 *
 * @return a WorkflowDocument object through which to interact with the loaded workflow document
 *
 * @throws IllegalArgumentException if principalId is null or blank
 * @throws IllegalArgumentException if documentTypeName is null or blank
 * @throws IllegalDocumentTypeException if the specified document type is not active
 * @throws IllegalDocumentTypeException if the specified document type does not support document
 *         creation (in other words, it's a document type that is only used as a parent)
 * @throws InvalidActionTakenException if the supplied principal is not allowed to execute this
 *         action
 * @see org.kuali.rice.kew.impl.document.WorkflowDocumentProvider#loadDocument(String, String)
 */
public static WorkflowDocument loadDocument(String principalId, String documentId) {
    if (StringUtils.isBlank(principalId)) {
        throw new IllegalArgumentException("principalId was null or blank");
    }
    if (StringUtils.isBlank(documentId)) {
        throw new IllegalArgumentException("documentId was null or blank");
    }

    Object workflowDocument = null;

    try {
        workflowDocument = ProviderHolder.loadMethod.invoke(ProviderHolder.provider, principalId, documentId);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("Failed to invoke " + LOAD_METHOD_NAME, e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw new ConfigurationException("Failed to invoke " + LOAD_METHOD_NAME, e);
    }

    if (!(workflowDocument instanceof WorkflowDocument)) {
        throw new ConfigurationException("Loaded document is not a proper instance of " + WorkflowDocument.class
                + ", was instead " + workflowDocument.getClass());
    }
    return (WorkflowDocument) workflowDocument;
}

From source file:org.kuali.rice.kew.api.WorkflowDocumentFactory.java

/**
 * Creates a new workflow document of the given type with the given initiator.
 *
 * @param principalId the document initiator
 * @param documentTypeName the document type
 * @param documentUpdate pre-constructed state with which to initialize the document
 * @param documentContentUpdate pre-constructed document content with which to initialize the document
 *
 * @return a WorkflowDocument object through which to interact with the new workflow document
 * // w  w  w .j ava2s .c om
 * @throws IllegalArgumentException if principalId is null or blank
 * @throws IllegalArgumentException if documentTypeName is null or blank
 * @throws IllegalDocumentTypeException if documentTypeName does not represent a valid document type
 * @see org.kuali.rice.kew.impl.document.WorkflowDocumentProvider#createDocument(String, String, DocumentUpdate, DocumentContentUpdate)
 */
public static WorkflowDocument createDocument(String principalId, String documentTypeName,
        DocumentUpdate documentUpdate, DocumentContentUpdate documentContentUpdate) {
    if (StringUtils.isBlank(principalId)) {
        throw new IllegalArgumentException("principalId was null or blank");
    }
    if (StringUtils.isBlank(documentTypeName)) {
        throw new IllegalArgumentException("documentTypeName was null or blank");
    }

    Object workflowDocument = null;

    try {
        workflowDocument = ProviderHolder.createMethod.invoke(ProviderHolder.provider, principalId,
                documentTypeName, documentUpdate, documentContentUpdate);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("Failed to invoke " + CREATE_METHOD_NAME, e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw new ConfigurationException("Failed to invoke " + CREATE_METHOD_NAME, e);
    }

    if (!(workflowDocument instanceof WorkflowDocument)) {
        throw new ConfigurationException("Created document is not a proper instance of "
                + WorkflowDocument.class + ", was instead " + workflowDocument.getClass());
    }
    return (WorkflowDocument) workflowDocument;
}

From source file:com.zigbee.framework.common.util.BeanCopyUtil.java

/**
 * Apache Copy Properties/*from www.ja  v a 2 s  . c  om*/
 * @Date        :      2011-8-5
 * @param srcBean source bean instance
 * @param destBean destination bean instance
 * @throws AppException
 */
public static void beanCopyProperties(Object srcBean, Object destBean) throws AppException {
    try {
        org.apache.commons.beanutils.BeanUtils.copyProperties(destBean, srcBean);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        String errMsg = "BEAN COPY Exception!" + e.getMessage() + e.getStackTrace();
        throw new AppException(CommonErrorConstants.BEAN_COPY_EXCEPTION, errMsg, e.getCause());
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        String errMsg = "BEAN COPY Exception!" + e.getMessage() + e.getStackTrace();
        throw new AppException(CommonErrorConstants.BEAN_COPY_EXCEPTION, errMsg, e.getCause());
    }
}

From source file:com.asakusafw.runtime.compatibility.JobCompatibility.java

/**
 * Sets the job ID to the job object.//from   w  w  w.  j  a v a2 s  .  com
 * @param job the job object
 * @param id the job ID
 * @throws IllegalArgumentException if some parameters were {@code null}
 * @since 0.7.1
 */
public static void setJobId(Job job, JobID id) {
    if (job == null) {
        throw new IllegalArgumentException("job must not be null"); //$NON-NLS-1$
    }
    if (id == null) {
        throw new IllegalArgumentException("id must not be null"); //$NON-NLS-1$
    }
    if (SET_JOB_ID != null) {
        try {
            SET_JOB_ID.invoke(job, id);
        } catch (IllegalAccessException e) {
            throw new UnsupportedOperationException(e);
        } catch (InvocationTargetException e) {
            throw new UnsupportedOperationException(e.getCause());
        }
    } else {
        throw new UnsupportedOperationException();
    }
}

From source file:com.mani.cucumber.ReflectionUtils.java

/**
 * Uses reflection to evaluate a single element of a path expression on
 * the given object. If the object is a list and the expression is a
 * number, this returns the expression'th element of the list. Otherwise,
 * this looks for a method named "get${expression}" and returns the result
 * of calling it./*from  w ww  .  j a v  a  2  s  .  c  o  m*/
 *
 * @param target the object to evaluate the expression against
 * @param expression the expression to evaluate
 * @return the result of evaluating the expression
 */
private static Object evaluate(Object target, String expression) {
    try {
        if (target instanceof List) {

            List<?> list = (List<?>) target;

            int index = Integer.parseInt(expression);
            if (index < 0) {
                index += list.size();
            }

            return list.get(index);

        } else {

            Method getter = findAccessor(target, expression);
            if (getter == null) {
                return null;
            }

            return getter.invoke(target);

        }
    } catch (IllegalAccessException exception) {
        throw new IllegalStateException("BOOM", exception);

    } catch (InvocationTargetException exception) {
        if (exception.getCause() instanceof RuntimeException) {
            throw (RuntimeException) exception.getCause();
        }
        throw new RuntimeException("BOOM", exception);
    }
}