Example usage for java.lang Error getSuppressed

List of usage examples for java.lang Error getSuppressed

Introduction

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

Prototype

public final synchronized Throwable[] getSuppressed() 

Source Link

Document

Returns an array containing all of the exceptions that were suppressed, typically by the try -with-resources statement, 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;
        }// w w  w  . j  a  va  2s  .c  o m
        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);
}