-
Notifications
You must be signed in to change notification settings - Fork 1.5k
SimpleJpaRepository.delete(Specification<T> spec)
throws NullPointerException
#2796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We have a problem in that area indeed because the |
SimpleJpaRepository.delete(Specification<T> spec)
throws NullPointerException
In its actual sense, this is not a bug because the documentation says that the specification is expected to be non-null and the argument is not defined as |
Add since tag. See spring-projects#2796
@mp911de thank you for patching this issue. When do you anticipate a new version will be cut with this fix? |
Check out the release calendar for our schedule at https://calendar.spring.io/. The next release will be |
@mp911de thanks for this fix! I believe that the problem mentioned by @xsg22 still exists. The problem is that the @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();
} This happens with Example: repository.delete(
Specification.allOf(
MySpecifications.hasId(id),
...
)
) I wonder if this is a Kotlin problem as I see no null check. I am happy for any info on this problem! |
|
Thank you for clarifying! |
I've had this problem too, so what's the latest solution? thanks |
I've just ran into the same issue. The root problem seems to be that the nullability contract of myRepository.delete { root, _, builder ->
/* build a predicate */
} ... will throw a NPE in Kotlin because of eager nullability checks that don't exist in pure Java. However, it's possible to implement a band-aid fix by explicitly providing a nullable type hint for the unused myRepository.delete { root, _: Any?, builder ->
/* build a predicate */
} I guess manually providing type hints overrides the nullability contract of |
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
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.
Thanks for any ideas for smooth workarounds or other input,
Leon
The text was updated successfully, but these errors were encountered: