Closed ghillert closed 1 year ago
Yeah, the exception is not the friendliest, because it has occurred during remote lambda invocation, but it is the correct one.
There are no guarantees that the value is not going to be null
, so the code should check for that (and typically create a new instance to update):
this.taskRepository.update(id, myModel -> {
if (myModel == null) {
myModel = new MyModel(id);
}
myModel.setDescription(description);
return myModel;
});
Which can also be done using one of the update
method overloads, which allow you to specify a value supplier that should be used to create a new value instance when the existing value is null
:
this.taskRepository.update(id, MyModel::setDescription, description, MyModel::new);
@aseovic Just revisiting this a bit more. The relevant code is in AbstractRepositoryBase
in Coherence package com.oracle.coherence.repository
:
if (entity == null && factory != null)
{
entity = factory.create(entry.getKey());
}
updater.update(entity, value);
I would think that if the entity is null and the factory is null, an IllegalStateException should be throw, without calling the updater with a null argument causing the nullpointerexception.
Added some documentation explain the situation plus work-around.
When doing an update for a non-existing
id
viaCoherenceRepository
using e.g.:then a
NullPointerException
is thrown:We should throw a more business-friendly exception, possibly even considering returning Spring data exceptions:
See: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/dao/package-summary.html