public static void rethrowRuntimeException(Throwable ex) {
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        if (ex instanceof Error) {
            throw (Error) ex;
        }
        throw new UndeclaredThrowableException(ex);
    }
Rethrow the given {link Throwable exception}, which is presumably the
<em>target exception</em> of an {link InvocationTargetException}.
Should only be called if no checked exception is expected to be thrown
by the target method.
<p>Rethrows the underlying exception cast to a {link RuntimeException} or
{link Error} if appropriate; otherwise, throws an
{link UndeclaredThrowableException}.

@param ex the exception to rethrow
@throws RuntimeException the rethrown exception
analyzer/src/main/java/nl/basjes/parse/useragent/utils/springframework/util/ReflectionUtils.java