Add missing null check for metadata.

1. null check on variable `metadata` is missing in method `existsById`
2. `CrudMethodMetadata::getComment` should be `@Nullable`

Closes #2991
Original pull request: #2995
This commit is contained in:
Yanming Zhou
2023-06-02 16:08:43 +08:00
committed by Mark Paluch
parent 280726fe2b
commit 168d7d56d3
3 changed files with 5 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.lang.Nullable;
* @author Mark Paluch
* @author Jens Schauder
* @author Greg Turnquist
* @author Yanming Zhou
*/
public interface CrudMethodMetadata {
@@ -66,6 +67,7 @@ public interface CrudMethodMetadata {
* @return
* @since 3.0
*/
@Nullable
String getComment();
/**

View File

@@ -56,6 +56,7 @@ import org.springframework.util.ReflectionUtils;
* @author Christoph Strobl
* @author Mark Paluch
* @author Jens Schauder
* @author Yanming Zhou
*/
class CrudMethodMetadataPostProcessor implements RepositoryProxyPostProcessor, BeanClassLoaderAware {
@@ -181,7 +182,7 @@ class CrudMethodMetadataPostProcessor implements RepositoryProxyPostProcessor, B
private final @Nullable LockModeType lockModeType;
private final org.springframework.data.jpa.repository.support.QueryHints queryHints;
private final org.springframework.data.jpa.repository.support.QueryHints queryHintsForCount;
private final String comment;
private final @Nullable String comment;
private final Optional<EntityGraph> entityGraph;
private final Method method;

View File

@@ -370,14 +370,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
TypedQuery<Long> query = em.createQuery(existsQuery, Long.class);
Map<String, Object> hints = new HashMap<>();
getQueryHints().withFetchGraphs(em).forEach(hints::put);
if (metadata.getComment() != null && provider.getCommentHintKey() != null) {
hints.put(provider.getCommentHintKey(), provider.getCommentHintValue(metadata.getComment()));
}
hints.forEach(query::setHint);
applyQueryHints(query);
if (!entityInformation.hasCompositeId()) {
query.setParameter(idAttributeNames.iterator().next(), id);