Perform NullAway build-time checks in more modules

This commit enables null-safety build-time checks in:
 - spring-jdbc
 - spring-r2dbc
 - spring-orm
 - spring-beans
 - spring-aop

See gh-32475
This commit is contained in:
Sébastien Deleuze
2024-03-26 09:55:41 +01:00
parent 3b4f8dbb8e
commit 5b660da52d
46 changed files with 78 additions and 12 deletions

View File

@@ -42,6 +42,7 @@ public class HibernateJdbcException extends UncategorizedDataAccessException {
/**
* Return the underlying SQLException.
*/
@SuppressWarnings("NullAway")
public SQLException getSQLException() {
return ((JDBCException) getCause()).getSQLException();
}
@@ -50,6 +51,7 @@ public class HibernateJdbcException extends UncategorizedDataAccessException {
* Return the SQL that led to the problem.
*/
@Nullable
@SuppressWarnings("NullAway")
public String getSql() {
return ((JDBCException) getCause()).getSQL();
}

View File

@@ -40,6 +40,7 @@ public class HibernateQueryException extends InvalidDataAccessResourceUsageExcep
* Return the HQL query string that was invalid.
*/
@Nullable
@SuppressWarnings("NullAway")
public String getQueryString() {
return ((QueryException) getCause()).getQueryString();
}

View File

@@ -947,6 +947,7 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
@Deprecated
@Override
@SuppressWarnings("NullAway")
public List<?> findByNamedQueryAndNamedParam(
String queryName, @Nullable String[] paramNames, @Nullable Object[] values)
throws DataAccessException {

View File

@@ -427,7 +427,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
if (cause != null) {
String message = ex.getMessage();
String causeString = cause.toString();
if (!message.endsWith(causeString)) {
if (message != null && !message.endsWith(causeString)) {
ex = new PersistenceException(message + "; nested exception is " + causeString, cause);
}
}

View File

@@ -349,7 +349,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
@Override
public void afterPropertiesSet() throws PersistenceException {
PersistenceUnitManager managerToUse = this.persistenceUnitManager;
if (this.persistenceUnitManager == null) {
if (managerToUse == null) {
this.internalPersistenceUnitManager.afterPropertiesSet();
managerToUse = this.internalPersistenceUnitManager;
}

View File

@@ -452,6 +452,7 @@ public class DefaultPersistenceUnitManager
* @see #obtainDefaultPersistenceUnitInfo()
* @see #obtainPersistenceUnitInfo(String)
*/
@SuppressWarnings("NullAway")
public void preparePersistenceUnitInfos() {
this.persistenceUnitInfoNames.clear();
this.persistenceUnitInfos.clear();

View File

@@ -359,6 +359,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
}
@Override
@Nullable
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
Class<?> beanClass = registeredBean.getBeanClass();
String beanName = registeredBean.getBeanName();
@@ -857,6 +858,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER);
}
@SuppressWarnings("NullAway")
private void generateGetEntityManagerMethod(MethodSpec.Builder method, PersistenceElement injectedElement) {
String unitName = injectedElement.unitName;
Properties properties = injectedElement.properties;

View File

@@ -36,6 +36,7 @@ import org.hibernate.property.access.spi.PropertyAccess;
final class Target_BytecodeProvider {
@Substitute
@SuppressWarnings("NullAway")
public ReflectionOptimizer getReflectionOptimizer(Class<?> clazz, Map<String, PropertyAccess> propertyAccessMap) {
return null;
}

View File

@@ -36,6 +36,7 @@ import org.hibernate.bytecode.spi.BytecodeProvider;
final class Target_BytecodeProviderInitiator {
@Alias
@SuppressWarnings("NullAway")
public static String BYTECODE_PROVIDER_NAME_NONE;
@Alias