Browse Source

Refine null-safety in the spring-orm module

Closes gh-34159
pull/34171/head
Sébastien Deleuze 12 months ago
parent
commit
73b24b6f7b
  1. 4
      spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateJdbcException.java
  2. 4
      spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateQueryException.java
  3. 2
      spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java
  4. 6
      spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java
  5. 2
      spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

4
spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateJdbcException.java

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

4
spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateQueryException.java

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

2
spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java

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

6
spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java

@ -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) { private void registerForReflection(ReflectionHints reflection, @Nullable Annotation annotation, String attribute) {
if (annotation == null) { if (annotation == null) {
return; return;
} }
Class<?> embeddableInstantiatorClass = (Class<?>) AnnotationUtils.getAnnotationAttributes(annotation).get(attribute); Class<?> type = (Class<?>) AnnotationUtils.getAnnotationAttributes(annotation).get(attribute);
reflection.registerType(embeddableInstantiatorClass, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); reflection.registerType(type, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
} }
} }
} }

2
spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

@ -848,7 +848,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER); 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) { private void generateGetEntityManagerMethod(MethodSpec.Builder method, PersistenceElement injectedElement) {
String unitName = injectedElement.unitName; String unitName = injectedElement.unitName;
Properties properties = injectedElement.properties; Properties properties = injectedElement.properties;

Loading…
Cancel
Save