Skip to content

Commit

Permalink
Refine null-safety in the spring-orm module
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Dec 26, 2024
1 parent abccba2 commit 73b24b6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public HibernateJdbcException(JDBCException ex) {
/**
* Return the underlying SQLException.
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // JDBCException instances always have a non null cause
public SQLException getSQLException() {
return ((JDBCException) getCause()).getSQLException();
}

/**
* 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public HibernateQueryException(QueryException ex) {
/**
* 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public void afterPropertiesSet() {
* @see #obtainDefaultPersistenceUnitInfo()
* @see #obtainPersistenceUnitInfo(String)
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
public void preparePersistenceUnitInfos() {
this.persistenceUnitInfoNames.clear();
this.persistenceUnitInfos.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ private void contributeHibernateHints(RuntimeHints hints, @Nullable ClassLoader
}
}

@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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ private CodeBlock generateResourceToInjectCode(
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;
Expand Down

0 comments on commit 73b24b6

Please sign in to comment.