This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch SLING-9552
in repository https://gitbox.apache.org/repos/asf/sling-jspc-maven-plugin.git

commit ed44902401fc196a54c56c441ea7fe3564dd8136
Author: Karl Pauls <[email protected]>
AuthorDate: Thu Jun 25 21:44:52 2020 +0200

    SLING-9552: make the JspCTldLocationsCache thread save.
---
 pom.xml                                            |  4 ++--
 .../sling/maven/jspc/JspCTldLocationsCache.java    | 25 +++++++++++++++-------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0f62a9c..83a1cd7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,13 +119,13 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.jsp</artifactId>
-            <version>2.5.1-SNAPSHOT</version>
+            <version>2.5.0</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.compiler</artifactId>
-            <version>2.4.1-SNAPSHOT</version>
+            <version>2.4.0</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
diff --git 
a/src/main/java/org/apache/sling/maven/jspc/JspCTldLocationsCache.java 
b/src/main/java/org/apache/sling/maven/jspc/JspCTldLocationsCache.java
index bd62cc8..376e880 100644
--- a/src/main/java/org/apache/sling/maven/jspc/JspCTldLocationsCache.java
+++ b/src/main/java/org/apache/sling/maven/jspc/JspCTldLocationsCache.java
@@ -30,6 +30,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
@@ -96,7 +97,7 @@ public class JspCTldLocationsCache extends TldLocationsCache {
     private static final String TLD_SCHEME = "tld:";
 
     // Names of JARs that are known not to contain any TLDs
-    private static HashSet<String> noTldJars;
+    private static final HashSet<String> noTldJars;
 
     /**
      * The mapping of the 'global' tag library URI to the location (resource
@@ -105,14 +106,15 @@ public class JspCTldLocationsCache extends 
TldLocationsCache {
      *    [0] The location
      *    [1] If the location is a jar file, this is the location of the tld.
      */
-    private Map<String, String[]> mappings;
+    private final Map<String, String[]> mappings;
 
-    private boolean initialized;
-    private ServletContext ctxt;
-    private boolean redeployMode;
+    private final ServletContext ctxt;
+    private final boolean redeployMode;
 
     private final ClassLoader webappLoader;
 
+    private volatile boolean initialized;
+
     //*********************************************************************
     // Constructor and Initilizations
 
@@ -179,7 +181,7 @@ public class JspCTldLocationsCache extends 
TldLocationsCache {
     public JspCTldLocationsCache(ServletContext ctxt, boolean redeployMode, 
ClassLoader loader) {
         this.ctxt = ctxt;
         this.redeployMode = redeployMode;
-        mappings = new HashMap<String, String[]>();
+        mappings = new ConcurrentHashMap<>();
         initialized = false;
         this.webappLoader = loader;
     }
@@ -227,7 +229,14 @@ public class JspCTldLocationsCache extends 
TldLocationsCache {
     public URL getTldLocationURL(String tldLocation) {
         if (tldLocation.startsWith(TLD_SCHEME)) {
             tldLocation = tldLocation.substring(TLD_SCHEME.length());
-            String[] locationInfo = mappings.get(tldLocation);
+            String[] locationInfo = null;
+
+            try {
+                locationInfo = getLocation(tldLocation);
+            } catch (JasperException ex) {
+                log.error("Cannot retrieve TLD location url for " + 
tldLocation + ".");
+                log.debug("Details:", ex);
+            }
             if (locationInfo != null) {
                 try {
                     if (locationInfo.length == 2) {
@@ -263,7 +272,7 @@ public class JspCTldLocationsCache extends 
TldLocationsCache {
         }
     }
 
-    private void init() throws JasperException {
+    private synchronized void init() throws JasperException {
         if (initialized) return;
         try {
             processWebDotXml();

Reply via email to