@Test void testInjectException() { assertThrows(IllegalArgumentException.class, () -> Util.inject(new Service2(), new Object(), FieldUtils.getField(Service2.class, "service1", true))); Util.inject(new Service2(), null, FieldUtils.getField(Service2.class, "service1", true)); }
public static void inject(@Nonnull Object instance, @Nullable Object object, @Nonnull Field field) { if (object != null && !field.getType().isAssignableFrom(object.getClass())) { throw new IllegalArgumentException( "the object doesn't have the correct type to be assigable to the given field. The object is of type " + object.getClass() + " and the field of " + field.getType()); } try { FieldUtils.writeField(field, instance, object, true); } catch (IllegalAccessException e) { throw new InjectionException(object, instance, e); } }
Util { public static void inject(@Nonnull Object instance, @Nullable Object object, @Nonnull Field field) { if (object != null && !field.getType().isAssignableFrom(object.getClass())) { throw new IllegalArgumentException( "the object doesn't have the correct type to be assigable to the given field. The object is of type " + object.getClass() + " and the field of " + field.getType()); } try { FieldUtils.writeField(field, instance, object, true); } catch (IllegalAccessException e) { throw new InjectionException(object, instance, e); } } }
Util { public static void inject(@Nonnull Object instance, @Nullable Object object, @Nonnull Field field) { if (object != null && !field.getType().isAssignableFrom(object.getClass())) { throw new IllegalArgumentException( "the object doesn't have the correct type to be assigable to the given field. The object is of type " + object.getClass() + " and the field of " + field.getType()); } try { FieldUtils.writeField(field, instance, object, true); } catch (IllegalAccessException e) { throw new InjectionException(object, instance, e); } } private  Util(); }
Util { public static void inject(@Nonnull Object instance, @Nullable Object object, @Nonnull Field field) { if (object != null && !field.getType().isAssignableFrom(object.getClass())) { throw new IllegalArgumentException( "the object doesn't have the correct type to be assigable to the given field. The object is of type " + object.getClass() + " and the field of " + field.getType()); } try { FieldUtils.writeField(field, instance, object, true); } catch (IllegalAccessException e) { throw new InjectionException(object, instance, e); } } private  Util(); static boolean isValidServiceClass(@Nonnull Class<?> cls); static boolean hasValidConstructors(@Nonnull Class<?> cls); static void postConstruct(@Nonnull Object instance); static void preDestroy(@Nonnull Object destroyMe); static void callAnnotatedMethods(@Nonnull Object instance,
			@Nonnull Class<? extends Annotation> annotationCls); static boolean isValidAnnotatedMethod(@Nonnull Method method); static void inject(@Nonnull Object instance, @Nullable Object object, @Nonnull Field field); static ServiceDescription<?> serviceDescriptionFor(Field field); }
Util { public static void inject(@Nonnull Object instance, @Nullable Object object, @Nonnull Field field) { if (object != null && !field.getType().isAssignableFrom(object.getClass())) { throw new IllegalArgumentException( "the object doesn't have the correct type to be assigable to the given field. The object is of type " + object.getClass() + " and the field of " + field.getType()); } try { FieldUtils.writeField(field, instance, object, true); } catch (IllegalAccessException e) { throw new InjectionException(object, instance, e); } } private  Util(); static boolean isValidServiceClass(@Nonnull Class<?> cls); static boolean hasValidConstructors(@Nonnull Class<?> cls); static void postConstruct(@Nonnull Object instance); static void preDestroy(@Nonnull Object destroyMe); static void callAnnotatedMethods(@Nonnull Object instance,
			@Nonnull Class<? extends Annotation> annotationCls); static boolean isValidAnnotatedMethod(@Nonnull Method method); static void inject(@Nonnull Object instance, @Nullable Object object, @Nonnull Field field); static ServiceDescription<?> serviceDescriptionFor(Field field);  }