Skip to content

Commit 7dce3d1

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

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ private <S> TypedQuery<S> applyRepositoryMethodMetadata(TypedQuery<S> query) {
829829

830830
private void applyQueryHints(Query query) {
831831

832+
if (metadata == null) {
833+
return;
834+
}
835+
832836
getQueryHints().withFetchGraphs(em).forEach(query::setHint);
833837

834838
if (metadata.getComment() != null && provider.getCommentHintKey() != null) {
@@ -849,6 +853,10 @@ private <S> TypedQuery<S> applyRepositoryMethodMetadataForCount(TypedQuery<S> qu
849853

850854
private void applyQueryHintsForCount(Query query) {
851855

856+
if (metadata == null) {
857+
return;
858+
}
859+
852860
getQueryHintsForCount().forEach(query::setHint);
853861

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

0 commit comments

Comments
 (0)