Skip to content

Commit 26bf33a

Browse files
committed
HHH-12529 - Some StatisticsImpl methods throw an exception instead of returning null
1 parent e2ac4eb commit 26bf33a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,12 @@ public CacheRegionStatisticsImpl getCacheRegionStatistics(String regionName) {
625625
return l2CacheStatsMap.computeIfAbsent(
626626
regionName,
627627
s -> {
628-
final Region region = sessionFactory.getCache().getRegion( regionName );
628+
Region region = sessionFactory.getCache().getRegion( regionName );
629629

630630
if ( region == null ) {
631-
throw new IllegalArgumentException( "Unknown cache region : " + regionName );
631+
// this is the pre-5.3 behavior. and since this is a pre-5.3 method it should behave consistently
632+
// NOTE that this method is deprecated
633+
region = sessionFactory.getCache().getQueryResultsCache( regionName ).getRegion();
632634
}
633635

634636
return new CacheRegionStatisticsImpl( region );
@@ -638,6 +640,9 @@ public CacheRegionStatisticsImpl getCacheRegionStatistics(String regionName) {
638640

639641
@Override
640642
public CacheRegionStatisticsImpl getSecondLevelCacheStatistics(String regionName) {
643+
if ( sessionFactory == null ) {
644+
return null;
645+
}
641646
return getCacheRegionStatistics( sessionFactory.getCache().unqualifyRegionName( regionName ) );
642647
}
643648

hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public void testLegacyStatsApi() {
8282

8383
final NaturalIdCacheStatistics naturalIdCacheStatistics = stats.getNaturalIdCacheStatistics( regionName );
8484
assert naturalIdCacheStatistics != null;
85+
86+
final SecondLevelCacheStatistics dne = stats.getSecondLevelCacheStatistics( cachePrefix + ".does.not.exist" );
87+
assert dne != null;
8588
}
8689

8790
// todo (5.3) : any other API I can think of that deals with region-name?

0 commit comments

Comments
 (0)