void (@NotNull Object host, @Nullable Object value) { if (myWriteMethod == null) { throw new SerializationException(host.getClass().getName() + "::" + myName + " lacks a setter"); } try { myWriteMethod.invoke(host, value); } catch (IllegalAccessException e) { throw new SerializationException(e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); // see KotlinXmlSerializerTest.nullInMap if (cause instanceof NullPointerException && myGenericType instanceof Class && ((Class<?>)myGenericType).isEnum() && cause.getMessage().contains("Parameter specified as non-null is null:")) { Object[] constants = ((Class<?>)myGenericType).getEnumConstants(); if (constants.length > 0) { try { LOG.warn("Cannot set enum value, will be set to first enum value", e); myWriteMethod.invoke(host, constants[0]); return; } catch (IllegalAccessException | InvocationTargetException e1) { throw new SerializationException(e); } } } throw new SerializationException(cause); } }