This looks broken in the usual way double-checked locking is broken. - Don't lazy init, or - Make the field volatile. - See also Effective Java by J Block Item, #83
Gary On Mon, Sep 15, 2025 at 11:07 AM <t...@apache.org> wrote: > > This is an automated email from the ASF dual-hosted git repository. > > tv pushed a commit to branch master > in repository https://gitbox.apache.org/repos/asf/commons-jcs.git > > commit f368d6797fb745f356c266bc5f4d59df2667f46c > Author: Thomas Vandahl <thomas.vand...@inverso.de> > AuthorDate: Mon Sep 15 17:06:10 2025 +0200 > > Use double-check locking > --- > .../src/main/java/org/apache/commons/jcs3/JCS.java | 35 > ++++++++++++---------- > 1 file changed, 19 insertions(+), 16 deletions(-) > > diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/JCS.java > b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/JCS.java > index cc7e8e71..a9e4a349 100644 > --- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/JCS.java > +++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/JCS.java > @@ -56,28 +56,31 @@ public abstract class JCS > */ > private static CompositeCacheManager getCacheManager() throws > CacheException > { > - synchronized ( JCS.class ) > + if ( cacheMgr == null || !cacheMgr.isInitialized()) > { > - if ( cacheMgr == null || !cacheMgr.isInitialized()) > + synchronized ( JCS.class ) > { > - if ( configProps != null ) > - { > - cacheMgr = > CompositeCacheManager.getUnconfiguredInstance(); > - cacheMgr.configure( configProps ); > - } > - else if ( configFileName != null ) > + if ( cacheMgr == null || !cacheMgr.isInitialized()) > { > - cacheMgr = > CompositeCacheManager.getUnconfiguredInstance(); > - cacheMgr.configure( configFileName ); > - } > - else > - { > - cacheMgr = CompositeCacheManager.getInstance(); > + if ( configProps != null ) > + { > + cacheMgr = > CompositeCacheManager.getUnconfiguredInstance(); > + cacheMgr.configure( configProps ); > + } > + else if ( configFileName != null ) > + { > + cacheMgr = > CompositeCacheManager.getUnconfiguredInstance(); > + cacheMgr.configure( configFileName ); > + } > + else > + { > + cacheMgr = CompositeCacheManager.getInstance(); > + } > } > } > - > - return cacheMgr; > } > + > + return cacheMgr; > } > > /** > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org