public static Serializable[] checkAndCorrectMessageArgs(final Object[] messageArgs, final Throwable setCauseOn,
                final boolean noExplicitCause) {
            Serializable[] retMessageArgs = EMPTY_SERIALIZABLE_ARRAY;
            // Set the message args.
            if (messageArgs != null && messageArgs.length > 0) {
                int length = messageArgs.length;
                if (messageArgs.length > 0 && noExplicitCause && messageArgs[length - 1] instanceof Throwable) {
                    // Backwards compatibility in case the exception is set as a message argument.
                    // This initCause will only be called if input cause is null
                    length = messageArgs.length - 1;
                    setCauseOn.initCause((Throwable) messageArgs[length]);
                }
                retMessageArgs = new Serializable[length];
                for (int i = 0; i < length; i++) {
                    Object arg = messageArgs[i];
                    if (arg instanceof Serializable) {
                        retMessageArgs[i] = (Serializable) arg;
                    } else if (arg != null) {
                        // The formatter will convert the argument to a String anyway so might as well reduce the object
                        // graph at this
                        // point.
                        try {
                            retMessageArgs[i] = arg.toString();
                        } catch (RuntimeException e) {
                            retMessageArgs[i] = "!" + e.getClass().getSimpleName() + " from toString():  "
                                    + e.getMessage() + "!";
                        }
                    } else {
                        // Arg is null, be explicit
                        retMessageArgs[i] = null;
                    }
                }
            }
            return retMessageArgs;
        }