code: 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: " + ex.getMessage());
          }
          if (ex instanceof InvocationTargetException) {
              handleInvocationTargetException((InvocationTargetException) ex);
          }
          if (ex instanceof RuntimeException) {
              throw (RuntimeException) ex;
          }
          throw new UndeclaredThrowableException(ex);
      }
docs: Handle the given reflection exception. Should only be called if no checked exception is expected to be thrown by the
  target method.
  <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