Refine null-safety in the spring-orm module

Closes gh-34159
This commit is contained in:
Sébastien Deleuze 2024-12-26 16:21:17 +01:00
parent abccba22f1
commit 73b24b6f7b
5 changed files with 9 additions and 9 deletions

View File

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

View File

@ -39,9 +39,9 @@ public class HibernateQueryException extends InvalidDataAccessResourceUsageExcep
/**
* Return the HQL query string that was invalid.
*/
@SuppressWarnings("NullAway")
public @Nullable String getQueryString() {
return ((QueryException) getCause()).getQueryString();
QueryException cause = (QueryException) getCause();
return cause == null ? null : cause.getQueryString();
}
}

View File

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

View File

@ -238,13 +238,13 @@ class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistr
}
}
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Not null assertion performed in ReflectionHints.registerType
private void registerForReflection(ReflectionHints reflection, @Nullable Annotation annotation, String attribute) {
if (annotation == null) {
return;
}
Class<?> embeddableInstantiatorClass = (Class<?>) AnnotationUtils.getAnnotationAttributes(annotation).get(attribute);
reflection.registerType(embeddableInstantiatorClass, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
Class<?> type = (Class<?>) AnnotationUtils.getAnnotationAttributes(annotation).get(attribute);
reflection.registerType(type, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
}
}
}

View File

@ -848,7 +848,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER);
}
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
private void generateGetEntityManagerMethod(MethodSpec.Builder method, PersistenceElement injectedElement) {
String unitName = injectedElement.unitName;
Properties properties = injectedElement.properties;