Example usage for java.lang Error addSuppressed

List of usage examples for java.lang Error addSuppressed

Introduction

In this page you can find the example usage for java.lang Error addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:org.nuxeo.runtime.test.runner.ConditionalIgnoreRule.java

protected void injectCondition(Class<?> type, Method method, Object target, Condition condition)
        throws SecurityException, Error {
    Error errors = new Error("Cannot inject condition parameters in " + condition.getClass());
    for (Field eachField : condition.getClass().getDeclaredFields()) {
        if (!eachField.isAnnotationPresent(Inject.class)) {
            continue;
        }//  ww  w .  j a va  2  s  .c om
        Object eachValue = null;
        if (eachField.isAnnotationPresent(Named.class)) {
            String name = eachField.getAnnotation(Named.class).value();
            if ("type".equals(name)) {
                eachValue = type;
            } else if ("target".equals(name)) {
                eachValue = target;
            } else if ("method".equals(name)) {
                eachValue = method;
            }
        } else {
            Class<?> eachType = eachField.getType();
            if (eachType.equals(Class.class)) {
                eachValue = type;
            } else if (eachType.equals(Object.class)) {
                eachValue = target;
            } else if (eachType.equals(Method.class)) {
                eachValue = method;
            }
        }
        if (eachValue == null) {
            continue;
        }
        eachField.setAccessible(true);
        try {
            eachField.set(condition, eachValue);
        } catch (IllegalArgumentException | IllegalAccessException cause) {
            errors.addSuppressed(new Error("Cannot inject " + eachField.getName(), cause));
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
    runner.getInjector().injectMembers(condition);
}