From e7d0bd095582aa0af55bdd0cc09714abc27c4d8e Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Thu, 1 Jun 2023 23:09:12 +0200 Subject: [PATCH] HHH-16515 - Add o.h.engine.profile to nullness checking Signed-off-by: Jan Schatteman --- gradle/java-module.gradle | 2 +- .../org/hibernate/engine/profile/DefaultFetchProfile.java | 4 +++- .../java/org/hibernate/engine/profile/FetchProfile.java | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gradle/java-module.gradle b/gradle/java-module.gradle index 0f04c975e5..df0756ac2f 100644 --- a/gradle/java-module.gradle +++ b/gradle/java-module.gradle @@ -525,7 +525,7 @@ checkerFramework { extraJavacArgs = [ '-AsuppressWarnings=initialization', "-Astubs=${project.rootDir}/checkerstubs", - '-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|(action|context|bytecode)\\.spi)\\.' + '-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|engine\\.profile|(action|context|bytecode)\\.spi)\\.' ] } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/profile/DefaultFetchProfile.java b/hibernate-core/src/main/java/org/hibernate/engine/profile/DefaultFetchProfile.java index d3d842e928..858ac701bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/profile/DefaultFetchProfile.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/profile/DefaultFetchProfile.java @@ -16,6 +16,8 @@ import org.hibernate.tuple.NonIdentifierAttribute; import java.util.Map; +import org.checkerframework.checker.nullness.qual.Nullable; + import static org.hibernate.engine.FetchStyle.SUBSELECT; import static org.hibernate.engine.FetchTiming.IMMEDIATE; import static org.hibernate.engine.FetchStyle.JOIN; @@ -36,7 +38,7 @@ public class DefaultFetchProfile extends FetchProfile { } @Override - public Fetch getFetchByRole(String role) { + public @Nullable Fetch getFetchByRole(String role) { final int last = role.lastIndexOf('.'); final String entityName = role.substring( 0, last ); final String property = role.substring( last + 1 ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/profile/FetchProfile.java b/hibernate-core/src/main/java/org/hibernate/engine/profile/FetchProfile.java index 8e0f059692..0cd02922b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/profile/FetchProfile.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/profile/FetchProfile.java @@ -16,6 +16,8 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.type.BagType; import org.hibernate.type.Type; +import org.checkerframework.checker.nullness.qual.Nullable; + import static org.hibernate.engine.FetchStyle.JOIN; import static org.hibernate.engine.FetchStyle.SUBSELECT; @@ -47,7 +49,7 @@ public class FetchProfile { private boolean containsJoinFetchedCollection; private boolean containsJoinFetchedBag; - private Fetch bagJoinFetch; + private @Nullable Fetch bagJoinFetch; /** * Constructs a {@link FetchProfile} with the given unique name. @@ -117,7 +119,7 @@ public class FetchProfile { // we need to go back and ignore that previous bag join fetch. if ( containsJoinFetchedBag ) { // just for safety... - if ( fetches.remove( bagJoinFetch.getAssociation().getRole() ) != bagJoinFetch ) { + if ( bagJoinFetch != null && fetches.remove( bagJoinFetch.getAssociation().getRole() ) != bagJoinFetch ) { LOG.unableToRemoveBagJoinFetch(); } bagJoinFetch = null; @@ -153,7 +155,7 @@ public class FetchProfile { * @return The {@code Fetch}, or {@code null} if there was * no {@code Fetch} for the given association */ - public Fetch getFetchByRole(String role) { + public @Nullable Fetch getFetchByRole(String role) { return fetches.get( role ); }