Skip to content

SimpleJPARepository: Methods accessing metadata.getComment() without Null-Check produce NPE #2716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jpeschke2608 opened this issue Nov 30, 2022 · 4 comments
Assignees
Labels
type: bug A general bug

Comments

@jpeschke2608
Copy link

Hi there,
Stumbled upon a Null Pointer Exception during Migration to Spring Boot 3.0.0 (and spring-data-jpa 3.0.0) that seems to be raised when accessing the "getComment" method on the metadata field of SimpleJPARepository:

The two methods "applyQueryHints" and "applyQueryHintsForCount()" don't perform a null check on the metadata field of SimpleJPARepository (which is annotated as @nullable), e.g.:

private void applyQueryHintsForCount(Query query) {
	getQueryHintsForCount().forEach(query::setHint);

       // NPE is thrown here, if metadata is null!
	if (metadata.getComment() != null && provider.getCommentHintKey() != null) {
		query.setHint(provider.getCommentHintKey(), provider.getCommentHintValue(metadata.getComment()));
	}
}

In other methods of the repository, it seems to be correct, e.g.:

private <S> TypedQuery<S> applyRepositoryMethodMetadata(TypedQuery<S> query) {
	if (metadata == null) {
	   return query;
	}
	LockModeType type = metadata.getLockModeType();
       ...
}	

Thanks for any ideas for smooth workarounds or other input,

Joerg

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 30, 2022
@jpeschke2608 jpeschke2608 changed the title SimpleJPARepository: Methos accessing metadata.getComment() without Null-Check produce NPE SimpleJPARepository: Methods accessing metadata.getComment() without Null-Check produce NPE Nov 30, 2022
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 5, 2022
@gregturn
Copy link
Contributor

gregturn commented Dec 5, 2022

Indeed, there are spots where the invoke of that method did a null check, but other spots where it does not.

@gregturn gregturn added this to the 3.0.1 (2022.0.1) milestone Dec 5, 2022
@gregturn
Copy link
Contributor

gregturn commented Dec 5, 2022

I added additional null checks in applyQueryHints and applyQueryHintsForCount to further guard against this.

@dickerpulli
Copy link

dickerpulli commented Jan 23, 2023

@gregturn Unfortunately the commits f40b39c and b0aa2b6 has not been pushed to the 3.0.x branch, so they were not a part of the 3.0.1 release. Could you please add them to the 3.0.x branch, so that they are at least included in next release 3.0.2?

Thanks.

P.S: Maybe @mp911de can do this also ... :-)

gregturn added a commit that referenced this issue Jan 30, 2023
It's possible to apply hints and hit a NullPointerException.

Resolves #2716.
@gregturn
Copy link
Contributor

I believe this was merged to main right after main rolled to 3.1.x. I've backported this fix to 3.0.x via 7dce3d1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants