Skip to content

Commit

Permalink
Add missing null check for metadata.
Browse files Browse the repository at this point in the history
1. null check on variable `metadata` is missing in method `existsById`
2. `CrudMethodMetadata::getComment` should be `@Nullable`

Closes #2991
Original pull request: #2995
  • Loading branch information
quaff authored and mp911de committed Jun 2, 2023
1 parent 28de271 commit 03cb819
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @author Mark Paluch
* @author Jens Schauder
* @author Greg Turnquist
* @author Yanming Zhou
*/
public interface CrudMethodMetadata {

Expand Down Expand Up @@ -66,6 +67,7 @@ public interface CrudMethodMetadata {
* @return
* @since 3.0
*/
@Nullable
String getComment();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @author Christoph Strobl
* @author Mark Paluch
* @author Jens Schauder
* @author Yanming Zhou
*/
class CrudMethodMetadataPostProcessor implements RepositoryProxyPostProcessor, BeanClassLoaderAware {

Expand Down Expand Up @@ -181,7 +182,7 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,7 @@ public boolean existsById(ID id) {

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);
Expand Down

0 comments on commit 03cb819

Please sign in to comment.