Skip to content
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

SimpleJpaRepository.delete(Specification<T> spec) throws NullPointerException [Kotlin] #3439

Closed
ASaludo opened this issue Apr 22, 2024 · 4 comments
Assignees
Labels
status: duplicate A duplicate of another issue

Comments

@ASaludo
Copy link

ASaludo commented Apr 22, 2024

Hello,

I have a problem using JpaSpecificationExecutor.delete using a Specification Object

I'm using Kotlin and the @nullable on top of the toPredicate function of Specification used line 477 with the null parameter of query seemed to be the problem

java.lang.NullPointerException: Parameter specified as non-null is null: ... at org.springframework.data.jpa.repository.support.SimpleJpaRepository.delete(SimpleJpaRepository.java:477)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 22, 2024
@christophstrobl
Copy link
Member

Thanks for reporting. Care to give us a bit more context of what you're trying to archive?
I do see a potential nullability contract violation with Specification#toPredicate when no CriteriaQuery is present due to CriteriaBuilder#createCriteriaDelete(Class) not implementing it.

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 22, 2024
@christophstrobl christophstrobl self-assigned this Apr 22, 2024
@ASaludo
Copy link
Author

ASaludo commented Apr 22, 2024

I'll give you all details :
Spring-jata-jpa : 3.2.5
Kotlin : 1.9.23

I'm trying to play this code :

    fun isToDelete(): Specification<Request> {
        return Specification<Entity> { root, _, builder ->
            LocalDateTime.now().minusDays(120)?.let { builder.lessThanOrEqualTo(root.get("date"), it) }
        }
    }
    fun delete() = entityRepository.delete(isToDelete())

But on the code of SimpleJpaRepository that implement the JpaSpecificationExecutor I hit the following line of code :

Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);`

with that interface :

	@Nullable
	Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);

I suspect that Kotlin don't take @nullable when compiling those java class and a NPE happen because "null" is literally passed to a non null parameter.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 22, 2024
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: feedback-provided Feedback has been provided labels Apr 25, 2024
@mp911de
Copy link
Member

mp911de commented Apr 25, 2024

That's a shortcoming of the Specification vs. Criteria Query design. Specifications have been designed for select queries and at some point, we enabled these for delete usage. We cannot provide a CriteriaQuery as CriteriaDelete isn't assignable into it. It's a duplicate of #3036.

At some point, we need to revisit our arrangement and find a path forward.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
@gbrehmer
Copy link

gbrehmer commented Jun 19, 2024

this means delete(spec) is currently not supported with kotlin or is there any known workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

5 participants