This bit:
ClassLoader fieldLoader = field.getType().getClassLoader();
ClassLoader valueLoader = value.getClass().getClassLoader();
boolean equalLoaders = fieldLoader.equals(valueLoader);
does not consider that the bootstrap ClassLoader may be represented as null by Class.getClassLoader in some JDK impls. Results in NPE.