Skip to content

Commit 5ffad14

Browse files
authored
Merge pull request #215 from basil/JellyClassLoaderTearOff
Migrate from Guava's cache to `ConcurrentHashMap` in `JellyClassLoaderTearOff`
2 parents 5f5221b + 2a74858 commit 5ffad14

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

jelly/src/main/java/org/kohsuke/stapler/jelly/JellyClassLoaderTearOff.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
package org.kohsuke.stapler.jelly;
2525

26-
import com.google.common.cache.CacheBuilder;
27-
import com.google.common.cache.CacheLoader;
28-
import com.google.common.cache.LoadingCache;
2926
import org.apache.commons.jelly.JellyContext;
3027
import org.apache.commons.jelly.JellyException;
3128
import org.apache.commons.jelly.TagLibrary;
@@ -35,6 +32,8 @@
3532

3633
import java.lang.ref.WeakReference;
3734
import java.net.URL;
35+
import java.util.concurrent.ConcurrentHashMap;
36+
import java.util.concurrent.ConcurrentMap;
3837

3938
/**
4039
* {@link MetaClassLoader} tear-off for Jelly support.
@@ -47,7 +46,7 @@ public class JellyClassLoaderTearOff {
4746
/**
4847
* See {@link JellyClassTearOff#scripts} for why we use {@link WeakReference} here.
4948
*/
50-
private volatile WeakReference<LoadingCache<String,TagLibrary>> taglibs;
49+
private volatile WeakReference<ConcurrentMap<String,TagLibrary>> taglibs;
5150

5251
static ExpressionFactory EXPRESSION_FACTORY = new JexlExpressionFactory();
5352

@@ -56,16 +55,18 @@ public JellyClassLoaderTearOff(MetaClassLoader owner) {
5655
}
5756

5857
public TagLibrary getTagLibrary(String nsUri) {
59-
LoadingCache<String,TagLibrary> m=null;
58+
ConcurrentMap<String,TagLibrary> m=null;
6059
if(taglibs!=null)
6160
m = taglibs.get();
6261
if(m==null) {
63-
m = CacheBuilder.newBuilder().build(new CacheLoader<String,TagLibrary>() {
64-
public TagLibrary load(String nsUri) {
62+
m = new ConcurrentHashMap<>();
63+
taglibs = new WeakReference<>(m);
64+
}
65+
TagLibrary tl = m.computeIfAbsent(nsUri, key -> {
6566
if(owner.parent!=null) {
6667
// parent first
67-
TagLibrary tl = owner.parent.loadTearOff(JellyClassLoaderTearOff.class).getTagLibrary(nsUri);
68-
if(tl!=null) return tl;
68+
TagLibrary taglib = owner.parent.loadTearOff(JellyClassLoaderTearOff.class).getTagLibrary(nsUri);
69+
if(taglib!=null) return taglib;
6970
}
7071

7172
String taglibBasePath = trimHeadSlash(nsUri);
@@ -90,12 +91,7 @@ public TagLibrary load(String nsUri) {
9091
return new StaplerTagLibrary();
9192

9293
return NO_SUCH_TAGLIBRARY; // "not found" is also cached.
93-
}
94-
});
95-
taglibs = new WeakReference<LoadingCache<String,TagLibrary>>(m);
96-
}
97-
98-
TagLibrary tl = m.getUnchecked(nsUri);
94+
});
9995
if (tl==NO_SUCH_TAGLIBRARY) return null;
10096
return tl;
10197
}

0 commit comments

Comments
 (0)