Skip to content

Commit b0aa2b6

Browse files
committed
Add additional null checks when applying hints.
It's possible to apply hints and hit a NullPointerException. Resolves #2716.
1 parent f40b39c commit b0aa2b6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java

+8
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,10 @@ private <S> TypedQuery<S> applyRepositoryMethodMetadata(TypedQuery<S> query) {
832832

833833
private void applyQueryHints(Query query) {
834834

835+
if (metadata == null) {
836+
return;
837+
}
838+
835839
getQueryHints().withFetchGraphs(em).forEach(query::setHint);
836840

837841
if (metadata.getComment() != null && provider.getCommentHintKey() != null) {
@@ -852,6 +856,10 @@ private <S> TypedQuery<S> applyRepositoryMethodMetadataForCount(TypedQuery<S> qu
852856

853857
private void applyQueryHintsForCount(Query query) {
854858

859+
if (metadata == null) {
860+
return;
861+
}
862+
855863
getQueryHintsForCount().forEach(query::setHint);
856864

857865
if (metadata.getComment() != null && provider.getCommentHintKey() != null) {

0 commit comments

Comments
 (0)