apereo/cas · warning

LoggingUtils.warn(LOGGER, e);

Error message

LoggingUtils.warn(LOGGER, e);

What it means

FunctionUtils.doAndHandle wraps a checked function into a lambda; on any Throwable from the wrapped function it logs a warning via LoggingUtils.warn and invokes the supplied errorHandler. If the error handler itself (or the logging) throws, the exception is rethrown wrapped in IllegalArgumentException(ex.getMessage()). The thrown IllegalArgumentException here is the nested-failure signal.

Solutions

  1. Make the errorHandler defensive: catch/log inside it or return a neutral fallback value instead of throwing.
  2. Inspect the IllegalArgumentException's cause/message (original ex.getMessage()) to identify the handler failure.
  3. Reorder logic so anticipated errors are handled before reaching the error handler.

Example fix

// before
FunctionUtils.doAndHandle(fn, err -> { throw new IllegalArgumentException(err); })
// after
FunctionUtils.doAndHandle(fn, err -> null) // or log-and-return-default
Defensive patterns

Strategy: fallback

Try / catch

R result = FunctionUtils.doAndHandle(fn, err -> defaultValue); // handler must not throw
// wrap the call site if the handler is fallible:
try { ... } catch (IllegalArgumentException e) { /* handler failed; inspect cause */ }

Prevention

When it happens

Trigger: The CheckedFunction passed to doAndHandle throws AND the provided errorHandler (CheckedFunction<Throwable,R>) also throws when handling it.

Common situations: Error handler performs its own fallible work (DB access, parsing, throwing GenericException) and fails; developers assume the handler result is a fallback but the handler itself raises.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.


AI-assisted analysis of apereo/cas@e7288fc434 (2026-09-08). Data as JSON: /api/errors/605924c1327d7e71. Report an issue: GitHub.

Appendix: source

Thrown at core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/function/FunctionUtils.java:353

    }

    /**
     * Default function.
     *
     * @param <T>          the type parameter
     * @param <R>          the type parameter
     * @param function     the function
     * @param errorHandler the error handler
     * @return the function
     */
    public static <T, R> Function<T, R> doAndHandle(final CheckedFunction<T, R> function,
                                                    final CheckedFunction<Throwable, R> errorHandler) {
        return t -> {
            try {
                return function.apply(t);
            } catch (final Throwable e) {
                try {
                    LoggingUtils.warn(LOGGER, e);
                    return errorHandler.apply(e);
                } catch (final Throwable ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }
        };
    }

    /**
     * Do and handle checked consumer.
     *
     * @param <R>          the type parameter
     * @param function     the function
     * @param errorHandler the error handler
     * @return the checked consumer
     */
    public static <R> Consumer<R> doAndHandle(final CheckedConsumer<R> function,
                                              final CheckedFunction<Throwable, R> errorHandler) {

View on GitHub (pinned to e7288fc434)