Skip to content

Commit cb5263c

Browse files
committed
avoid calling applyEntityGraph() with null argument
1 parent 8f37346 commit cb5263c

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

hibernate-core/src/main/java/org/hibernate/engine/spi/EffectiveEntityGraph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public EffectiveEntityGraph(boolean allowOverwrite) {
7474
* @throws IllegalArgumentException Thrown if the semantic is null
7575
* @throws IllegalStateException If previous state is still available (hasn't been cleared).
7676
*/
77-
public void applyGraph(RootGraphImplementor<?> graph, @Nullable GraphSemantic semantic) {
77+
public void applyGraph(RootGraphImplementor<?> graph, GraphSemantic semantic) {
7878
if ( semantic == null ) {
7979
throw new IllegalArgumentException( "Graph semantic cannot be null" );
8080
}

hibernate-core/src/main/java/org/hibernate/engine/spi/LoadQueryInfluencers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public LoadQueryInfluencers(SessionFactoryImplementor sessionFactory, SessionCre
8383
}
8484
}
8585

86-
public EffectiveEntityGraph applyEntityGraph(@Nullable RootGraphImplementor<?> rootGraph, @Nullable GraphSemantic graphSemantic) {
86+
public EffectiveEntityGraph applyEntityGraph(RootGraphImplementor<?> rootGraph, GraphSemantic graphSemantic) {
8787
final var effectiveEntityGraph = getEffectiveEntityGraph();
8888
if ( graphSemantic != null ) {
8989
if ( rootGraph == null ) {

hibernate-core/src/main/java/org/hibernate/internal/MultiIdentifierLoadAccessImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.hibernate.RemovalsMode;
1616
import org.hibernate.SessionCheckMode;
1717
import org.hibernate.UnknownProfileException;
18-
import org.hibernate.engine.spi.EffectiveEntityGraph;
19-
import org.hibernate.engine.spi.LoadQueryInfluencers;
2018
import org.hibernate.engine.spi.SessionImplementor;
2119
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2220
import org.hibernate.graph.GraphSemantic;
@@ -170,7 +168,7 @@ public <K> List<T> multiLoad(K... ids) {
170168
}
171169

172170
public List<T> perform(Supplier<List<T>> executor) {
173-
final CacheMode sessionCacheMode = session.getCacheMode();
171+
final var sessionCacheMode = session.getCacheMode();
174172
boolean cacheModeChanged = false;
175173
if ( cacheMode != null ) {
176174
// naive check for now...
@@ -182,16 +180,20 @@ public List<T> perform(Supplier<List<T>> executor) {
182180
}
183181

184182
try {
185-
final LoadQueryInfluencers influencers = session.getLoadQueryInfluencers();
186-
final HashSet<String> fetchProfiles =
183+
final var influencers = session.getLoadQueryInfluencers();
184+
final var fetchProfiles =
187185
influencers.adjustFetchProfiles( disabledFetchProfiles, enabledFetchProfiles );
188-
final EffectiveEntityGraph effectiveEntityGraph =
189-
influencers.applyEntityGraph( rootGraph, graphSemantic );
186+
final var effectiveEntityGraph =
187+
rootGraph == null
188+
? null
189+
: influencers.applyEntityGraph( rootGraph, graphSemantic );
190190
try {
191191
return executor.get();
192192
}
193193
finally {
194-
effectiveEntityGraph.clear();
194+
if ( effectiveEntityGraph != null ) {
195+
effectiveEntityGraph.clear();
196+
}
195197
influencers.setEnabledFetchProfileNames( fetchProfiles );
196198
}
197199
}

hibernate-core/src/main/java/org/hibernate/internal/NaturalIdMultiLoadAccessStandard.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import org.hibernate.NaturalIdMultiLoadAccess;
1717
import org.hibernate.OrderingMode;
1818
import org.hibernate.RemovalsMode;
19-
import org.hibernate.engine.spi.EffectiveEntityGraph;
20-
import org.hibernate.engine.spi.LoadQueryInfluencers;
2119
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2220
import org.hibernate.graph.GraphSemantic;
2321
import org.hibernate.graph.spi.RootGraphImplementor;
@@ -121,12 +119,12 @@ public List<T> multiLoad(Object... ids) {
121119
}
122120
}
123121

124-
final LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers();
122+
final var loadQueryInfluencers = session.getLoadQueryInfluencers();
125123

126124
try {
127-
final EffectiveEntityGraph effectiveEntityGraph = loadQueryInfluencers.getEffectiveEntityGraph();
128-
final GraphSemantic initialGraphSemantic = effectiveEntityGraph.getSemantic();
129-
final RootGraphImplementor<?> initialGraph = effectiveEntityGraph.getGraph();
125+
final var effectiveEntityGraph = loadQueryInfluencers.getEffectiveEntityGraph();
126+
final var initialGraphSemantic = effectiveEntityGraph.getSemantic();
127+
final var initialGraph = effectiveEntityGraph.getGraph();
130128
final boolean hadInitialGraph = initialGraphSemantic != null;
131129

132130
if ( graphSemantic != null ) {
@@ -137,7 +135,9 @@ public List<T> multiLoad(Object... ids) {
137135
}
138136

139137
try {
140-
return (List<T>) entityDescriptor.getMultiNaturalIdLoader().multiLoad( ids, this, session );
138+
return (List<T>)
139+
entityDescriptor.getMultiNaturalIdLoader()
140+
.multiLoad( ids, this, session );
141141
}
142142
finally {
143143
if ( graphSemantic != null ) {

hibernate-core/src/main/java/org/hibernate/loader/internal/BaseNaturalIdLoadAccessImpl.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,21 @@ protected final T doLoad(Object normalizedNaturalIdValue) {
174174
final var session = context.getSession();
175175
final var influencers = session.getLoadQueryInfluencers();
176176
final var fetchProfiles = influencers.adjustFetchProfiles( disabledFetchProfiles, enabledFetchProfiles );
177-
final var effectiveEntityGraph = influencers.applyEntityGraph( rootGraph, graphSemantic );
177+
final var effectiveEntityGraph =
178+
rootGraph == null
179+
? null
180+
: influencers.applyEntityGraph( rootGraph, graphSemantic );
178181
try {
179182
@SuppressWarnings("unchecked")
180183
final T loaded = cachedResolution != null
181-
? identifierLoadAccess().load(cachedResolution)
184+
? identifierLoadAccess().load( cachedResolution )
182185
: (T) entityPersister().getNaturalIdLoader()
183186
.load( normalizedNaturalIdValue, this, session );
184187
if ( loaded != null ) {
185188
final var persistenceContext = session.getPersistenceContextInternal();
186189
final var lazyInitializer = HibernateProxy.extractLazyInitializer( loaded );
187-
final var entry = lazyInitializer != null
188-
? persistenceContext.getEntry( lazyInitializer.getImplementation() )
189-
: persistenceContext.getEntry( loaded );
190+
final var entity = lazyInitializer != null ? lazyInitializer.getImplementation() : loaded;
191+
final var entry = persistenceContext.getEntry( entity );
190192
assert entry != null;
191193
if ( entry.getStatus() == Status.DELETED ) {
192194
return null;
@@ -196,7 +198,9 @@ protected final T doLoad(Object normalizedNaturalIdValue) {
196198
}
197199
finally {
198200
context.delayedAfterCompletion();
199-
effectiveEntityGraph.clear();
201+
if ( effectiveEntityGraph != null ) {
202+
effectiveEntityGraph.clear();
203+
}
200204
influencers.setEnabledFetchProfileNames( fetchProfiles );
201205
}
202206
}

hibernate-core/src/main/java/org/hibernate/loader/internal/IdentifierLoadAccessImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ protected T perform(Supplier<T> executor) {
121121
try {
122122
final var influencers = session.getLoadQueryInfluencers();
123123
final var fetchProfiles = influencers.adjustFetchProfiles( disabledFetchProfiles, enabledFetchProfiles );
124-
final var effectiveEntityGraph = influencers.applyEntityGraph( rootGraph, graphSemantic);
124+
final var effectiveEntityGraph =
125+
rootGraph == null
126+
? null
127+
: influencers.applyEntityGraph( rootGraph, graphSemantic);
125128
try {
126129
return executor.get();
127130
}
128131
finally {
129-
effectiveEntityGraph.clear();
132+
if ( effectiveEntityGraph != null ) {
133+
effectiveEntityGraph.clear();
134+
}
130135
influencers.setEnabledFetchProfileNames( fetchProfiles );
131136
}
132137
}

0 commit comments

Comments
 (0)