public static void handleReflectionException(Exception ex) {
        if (ex instanceof NoSuchMethodException) {
            throw new IllegalStateException("Method not found: " + ex.getMessage());
        }
        if (ex instanceof IllegalAccessException) {
            throw new IllegalStateException("Could not access method or field: " + ex.getMessage());
        }
        if (ex instanceof InvocationTargetException) {
            handleInvocationTargetException((InvocationTargetException) ex);
        }
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new UndeclaredThrowableException(ex);
    }
Handle the given reflection exception.
<p>Should only be called if no checked exception is expected to be thrown
by a target method, or if an error occurs while accessing a method or field.
<p>Throws the underlying RuntimeException or Error in case of an
InvocationTargetException with such a root cause. Throws an
IllegalStateException with an appropriate message or
UndeclaredThrowableException otherwise.

@param ex the reflection exception to handle
analyzer/src/main/java/nl/basjes/parse/useragent/utils/springframework/util/ReflectionUtils.java