Skip to content

Commit 9389df5

Browse files
committed
Add missing null check and @nullable
1. null check on variable `metadata` is missing in method `existsById` 2. `CrudMethodMetadata::getComment` should be `@Nullable` Fix spring-projectsGH-2991
1 parent 28de271 commit 9389df5

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @author Mark Paluch
3434
* @author Jens Schauder
3535
* @author Greg Turnquist
36+
* @author Yanming Zhou
3637
*/
3738
public interface CrudMethodMetadata {
3839

@@ -66,6 +67,7 @@ public interface CrudMethodMetadata {
6667
* @return
6768
* @since 3.0
6869
*/
70+
@Nullable
6971
String getComment();
7072

7173
/**

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* @author Christoph Strobl
5757
* @author Mark Paluch
5858
* @author Jens Schauder
59+
* @author Yanming Zhou
5960
*/
6061
class CrudMethodMetadataPostProcessor implements RepositoryProxyPostProcessor, BeanClassLoaderAware {
6162

@@ -181,7 +182,7 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
181182
private final @Nullable LockModeType lockModeType;
182183
private final org.springframework.data.jpa.repository.support.QueryHints queryHints;
183184
private final org.springframework.data.jpa.repository.support.QueryHints queryHintsForCount;
184-
private final String comment;
185+
private final @Nullable String comment;
185186
private final Optional<EntityGraph> entityGraph;
186187
private final Method method;
187188

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,7 @@ public boolean existsById(ID id) {
370370

371371
TypedQuery<Long> query = em.createQuery(existsQuery, Long.class);
372372

373-
Map<String, Object> hints = new HashMap<>();
374-
getQueryHints().withFetchGraphs(em).forEach(hints::put);
375-
376-
if (metadata.getComment() != null && provider.getCommentHintKey() != null) {
377-
hints.put(provider.getCommentHintKey(), provider.getCommentHintValue(metadata.getComment()));
378-
}
379-
380-
hints.forEach(query::setHint);
373+
applyQueryHints(query);
381374

382375
if (!entityInformation.hasCompositeId()) {
383376
query.setParameter(idAttributeNames.iterator().next(), id);

0 commit comments

Comments
 (0)