spring-projects / spring-projects/spring-data-commons
Consider individually annotated methods with non-null annotations for non-null validation [DATACMNS-1705]
Open
@odrotbohm is already working on this.
Since Feb 8, 2021.
status: waiting-for-triage
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
Dmitry Solomakha opened DATACMNS-1705 and commented
This behavior manifests itself in spring-data-jpa:
when there is a repository with a method that is annotated with org.springframework.lang.NonNull and the method returns null value, the EmptyResultDataAccessException exception is not thrown unless the class is annotated with javax.annotation.Nonnull.
Is that intentional?
This behavior is caused by MethodInvocationValidator class.
Reproduction with spring-data-jpa:
public interface CustomerRepository extends CrudRepository<Customer, Long> {
@NonNull
Customer findByLastName(String lastName);
}
@DataJpaTest
public class CustomerRepositoryTests {
@Autowired
private CustomerRepository customers;
@Test
public void testFindByLastName()
{ assertThatThrownBy(() -> customers.findByLastName("name")) .isInstanceOf(EmptyResultDataAccessException.class)
.hasMessageMatching("Result must not be null!");
}
}
No further details from DATACMNS-1705
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.