如果不抛出异常,JpaRepository 的 findAll() 是否保证 return 非空结果?

Is JpaRepository's findAll() guaranteed to return a non-null result if an exception isn't thrown?

documentation 在这一点上少得可怜。

嗯,org.springframework.data.repositoryPackage summary 表示 Non-Null APIS。这意味着它保证 return 来自该方法的非空类型的对象。

@NonNullAPI 告诉带有此注释的包是空安全的,API 使用不需要考虑处理空检查场景。

这已记录在案,请参阅第 Null Handling of Repository Methods of the Spring Data JPA documentation 部分:

Repository methods returning collections, collection alternatives, wrappers, and streams are guaranteed never to return null but rather the corresponding empty representation. See “Repository query return types” for details.

由于 Spring Data JPA 根据命名模式生成查询方法,JpaRepository 只是此类存储库的一个示例,因此在 JavaDoc 中记录它可能没有意义,但是相反,他们将其放在用户文档中。