Skip to content

Commit 3d27b29

Browse files
committed
HHH-9874 Improve resource lookup for the Infinispan configuration resources
1 parent d0d0963 commit 3d27b29

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate.cache.infinispan;
88

9-
import java.io.FileNotFoundException;
109
import java.io.IOException;
1110
import java.io.InputStream;
1211
import java.util.ArrayList;
@@ -47,6 +46,7 @@
4746

4847
import org.infinispan.AdvancedCache;
4948
import org.infinispan.commands.module.ModuleCommandFactory;
49+
import org.infinispan.commons.util.FileLookup;
5050
import org.infinispan.commons.util.FileLookupFactory;
5151
import org.infinispan.configuration.cache.CacheMode;
5252
import org.infinispan.configuration.cache.Configuration;
@@ -426,20 +426,20 @@ protected EmbeddedCacheManager createCacheManager(
426426
properties,
427427
DEF_INFINISPAN_CONFIG_RESOURCE
428428
);
429+
final FileLookup fileLookup = FileLookupFactory.newInstance();
429430

430431
return serviceRegistry.getService( ClassLoaderService.class ).workWithClassLoader(
431432
new ClassLoaderService.Work<EmbeddedCacheManager>() {
432433
@Override
433434
public EmbeddedCacheManager doWork(ClassLoader classLoader) {
434435
try {
435436
InputStream is;
436-
try {
437-
is = FileLookupFactory.newInstance().lookupFileStrict( configLoc, classLoader );
438-
}
439-
catch (FileNotFoundException e) {
440-
// In some environments (ex: OSGi), hibernate-infinispan may not
441-
// be in the app CL. It's important to also try this CL.
437+
is = fileLookup.lookupFile( configLoc, classLoader );
438+
if ( is == null ) {
439+
// when it's not a user-provided configuration file, it might be a default configuration file,
440+
// and if that's included in [this] module might not be visible to the ClassLoaderService:
442441
classLoader = this.getClass().getClassLoader();
442+
// This time use lookupFile*Strict* so to provide an exception if we can't find it yet:
443443
is = FileLookupFactory.newInstance().lookupFileStrict( configLoc, classLoader );
444444
}
445445
final ParserRegistry parserRegistry = new ParserRegistry( classLoader );

0 commit comments

Comments
 (0)