Skip to content

Commit 73b24b6

Browse files
committed
Refine null-safety in the spring-orm module
Closes gh-34159
1 parent abccba2 commit 73b24b6

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public HibernateJdbcException(JDBCException ex) {
4242
/**
4343
* Return the underlying SQLException.
4444
*/
45-
@SuppressWarnings("NullAway")
45+
@SuppressWarnings("NullAway") // JDBCException instances always have a non null cause
4646
public SQLException getSQLException() {
4747
return ((JDBCException) getCause()).getSQLException();
4848
}
4949

5050
/**
5151
* Return the SQL that led to the problem.
5252
*/
53-
@SuppressWarnings("NullAway")
53+
@SuppressWarnings("NullAway") // JDBCException instances always have a non null cause
5454
public @Nullable String getSql() {
5555
return ((JDBCException) getCause()).getSQL();
5656
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public HibernateQueryException(QueryException ex) {
3939
/**
4040
* Return the HQL query string that was invalid.
4141
*/
42-
@SuppressWarnings("NullAway")
4342
public @Nullable String getQueryString() {
44-
return ((QueryException) getCause()).getQueryString();
43+
QueryException cause = (QueryException) getCause();
44+
return cause == null ? null : cause.getQueryString();
4545
}
4646

4747
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public void afterPropertiesSet() {
435435
* @see #obtainDefaultPersistenceUnitInfo()
436436
* @see #obtainPersistenceUnitInfo(String)
437437
*/
438-
@SuppressWarnings("NullAway")
438+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
439439
public void preparePersistenceUnitInfos() {
440440
this.persistenceUnitInfoNames.clear();
441441
this.persistenceUnitInfos.clear();

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ private void contributeHibernateHints(RuntimeHints hints, @Nullable ClassLoader
238238
}
239239
}
240240

241-
@SuppressWarnings("NullAway")
241+
@SuppressWarnings("NullAway") // Not null assertion performed in ReflectionHints.registerType
242242
private void registerForReflection(ReflectionHints reflection, @Nullable Annotation annotation, String attribute) {
243243
if (annotation == null) {
244244
return;
245245
}
246-
Class<?> embeddableInstantiatorClass = (Class<?>) AnnotationUtils.getAnnotationAttributes(annotation).get(attribute);
247-
reflection.registerType(embeddableInstantiatorClass, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
246+
Class<?> type = (Class<?>) AnnotationUtils.getAnnotationAttributes(annotation).get(attribute);
247+
reflection.registerType(type, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
248248
}
249249
}
250250
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ private CodeBlock generateResourceToInjectCode(
848848
return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER);
849849
}
850850

851-
@SuppressWarnings("NullAway")
851+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
852852
private void generateGetEntityManagerMethod(MethodSpec.Builder method, PersistenceElement injectedElement) {
853853
String unitName = injectedElement.unitName;
854854
Properties properties = injectedElement.properties;

0 commit comments

Comments
 (0)