spring-projects / spring-projects/spring-data-commons

Consider individually annotated methods with non-null annotations for non-null validation [DATACMNS-1705]

Open
#2,104 1 comment 0 reactions 2 assignees View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.