Reflection { @SuppressWarnings("unchecked") public static <T> T invokeWithDefault(@Nullable Method method, Object obj, T defaultValue, @Nullable Object... args) { if (method == null) { return defaultValue; } try { Object value = method.invoke(obj, args); if (value == null) { return defaultValue; } return (T) value; } catch (Throwable t) { logger.warn("error calling {}.{}()", method.getDeclaringClass().getName(), method.getName(), t); return defaultValue; } } private  Reflection(); static @Nullable Class<?> getClass(String name, @Nullable ClassLoader loader); static @Nullable Class<?> getClassWithWarnIfNotFound(String name,
            @Nullable ClassLoader loader); static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName,
            Class<?>... parameterTypes); static @Nullable Field getDeclaredField(@Nullable Class<?> clazz, String fieldName); @SuppressWarnings("unchecked") static T invoke(@Nullable Method method, Object obj,
            @Nullable Object... args); @SuppressWarnings("unchecked") static T invokeWithDefault(@Nullable Method method, Object obj, T defaultValue,
            @Nullable Object... args); static @Nullable Object getFieldValue(@Nullable Field field, Object obj);  }
@Test public void shouldReturnDefaultValueWhenMethodIsNull() { assertThat(Reflection.invokeWithDefault(null, null, "the default")) .isEqualTo("the default"); }