-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Hi,
org.springframework.data.jpa.repository.support.SimpleJpaRepository#delete(Specification) throw s an NullPointerException when I execute in the kotlin language environment. More error messages like this
java.lang.NullPointerException: Parameter specified as non-null is null: method cn.sail.patient.controller.mutaion.ExerciseMutation.deleteExerciseRecord$lambda$0, parameter <anonymous parameter 1>
@Override
public long delete(Specification<T> spec) {
CriteriaBuilder builder = this.em.getCriteriaBuilder();
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);
if (predicate != null) {
delete.where(predicate);
}
return this.em.createQuery(delete).executeUpdate();
}
when executing "spec.toPredicate(delete.from(getDomainClass()), null, builder)", the second parameter passed in is null. However, the comment on the "Specification.toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder)" method clearly states that the ’query‘ parameter must not be null. If 'query' is null, the above exception will appear under kotlin because “CriteriaQuery query” is not a nullable type.
/**
* Creates a WHERE clause for a query of the referenced entity in form of a {@link Predicate} for the given
* {@link Root} and {@link CriteriaQuery}.
*
* @param root must not be {@literal null}.
* @param query must not be {@literal null}.
* @param criteriaBuilder must not be {@literal null}.
* @return a {@link Predicate}, may be {@literal null}.
*/
@Nullable
Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);
Thanks for any ideas for smooth workarounds or other input,
Leon
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug