33
33
import java .lang .reflect .Constructor ;
34
34
import java .lang .reflect .Field ;
35
35
import java .lang .reflect .Method ;
36
+ import java .lang .reflect .Modifier ;
36
37
import java .net .URL ;
37
38
import java .util .Collection ;
38
39
import java .util .HashMap ;
@@ -776,6 +777,9 @@ public CleanableSupplier<Collection<Class<?>>> getLoadedClassesRetriever(ClassLo
776
777
@ Override
777
778
public <T > T getFieldValue (Object target , Field field ) {
778
779
BiFunction <Object , Field , Object > fieldValueRetriever = this .fieldValueRetriever ;
780
+ if (target == null && !Modifier .isStatic (field .getModifiers ())) {
781
+ throw new IllegalArgumentException ("Target cannot be null when the field is not static" );
782
+ }
779
783
try {
780
784
return (T )fieldValueRetriever .apply (target , field );
781
785
} catch (NullPointerException exc ) {
@@ -796,6 +800,9 @@ public <T> T getFieldValue(Object target, Field field) {
796
800
@ Override
797
801
public void setFieldValue (Object target , Field field , Object value ) {
798
802
TriConsumer <Object , Field , Object > fieldValueSetter = this .fieldValueSetter ;
803
+ if (target == null && !Modifier .isStatic (field .getModifiers ())) {
804
+ throw new IllegalArgumentException ("Target cannot be null when the field is not static" );
805
+ }
799
806
try {
800
807
fieldValueSetter .accept (target , field , value );
801
808
} catch (NullPointerException exc ) {
0 commit comments