freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/3] incubator-freemarker git commit: Reverted source comparison bugfix for StringTemplateLoader and ByteArrayTemplateLoader; this thing will only causes problems in FM3, because in FM2 the MultiTemplateLoader has its own source class that compares the
Date Wed, 08 Feb 2017 01:01:05 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae b687c6d7e -> b1e28b0fe


Reverted source comparison bugfix for StringTemplateLoader and ByteArrayTemplateLoader; this
thing will only causes problems in FM3, because in FM2 the MultiTemplateLoader has its own
source class that compares the TemplateLoader-s too.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/708097f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/708097f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/708097f7

Branch: refs/heads/2.3-gae
Commit: 708097f70c1783c4df789ff376dc480af10d7f64
Parents: b687c6d
Author: ddekany <ddekany@apache.org>
Authored: Wed Feb 8 00:29:36 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Wed Feb 8 00:32:34 2017 +0100

----------------------------------------------------------------------
 .../freemarker/cache/ByteArrayTemplateLoader.java    | 15 +++------------
 .../java/freemarker/cache/StringTemplateLoader.java  | 14 +++-----------
 src/manual/en_US/book.xml                            |  9 ---------
 3 files changed, 6 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/708097f7/src/main/java/freemarker/cache/ByteArrayTemplateLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/cache/ByteArrayTemplateLoader.java b/src/main/java/freemarker/cache/ByteArrayTemplateLoader.java
index c089a85..84251fb 100644
--- a/src/main/java/freemarker/cache/ByteArrayTemplateLoader.java
+++ b/src/main/java/freemarker/cache/ByteArrayTemplateLoader.java
@@ -25,7 +25,6 @@ import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
 
 import freemarker.template.utility.StringUtil;
 
@@ -37,13 +36,10 @@ import freemarker.template.utility.StringUtil;
  */
 public class ByteArrayTemplateLoader implements TemplateLoader {
 
-    private static final AtomicLong INSTANCE_COUNTER = new AtomicLong();
-    
-    private final long instanceId = INSTANCE_COUNTER.incrementAndGet();
     private final Map<String, ByteArrayTemplateSource> templates = new HashMap<String,
ByteArrayTemplateSource>();
     
     /**
-     * Adds a template to this template loader; see {@link StringTemplateLoader#putTemplate(String,
String)} for mpre.
+     * Adds a template to this template loader; see {@link StringTemplateLoader#putTemplate(String,
String)} for more.
      */
     public void putTemplate(String name, byte[] templateSource) {
         putTemplate(name, templateSource, System.currentTimeMillis());
@@ -54,7 +50,7 @@ public class ByteArrayTemplateLoader implements TemplateLoader {
      * more.
      */
     public void putTemplate(String name, byte[] templateSource, long lastModified) {
-        templates.put(name, new ByteArrayTemplateSource(instanceId, name, templateSource,
lastModified));
+        templates.put(name, new ByteArrayTemplateSource(name, templateSource, lastModified));
     }
     
     /**
@@ -85,13 +81,11 @@ public class ByteArrayTemplateLoader implements TemplateLoader {
     }
     
     private static class ByteArrayTemplateSource {
-        private final long instanceId;
         private final String name;
         private final byte[] source;
         private final long lastModified;
         
-        ByteArrayTemplateSource(long instanceId, String name, byte[] source, long lastModified)
{
-            this.instanceId = instanceId;
+        ByteArrayTemplateSource(String name, byte[] source, long lastModified) {
             if (name == null) {
                 throw new IllegalArgumentException("name == null");
             }
@@ -110,7 +104,6 @@ public class ByteArrayTemplateLoader implements TemplateLoader {
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result + (int) (instanceId ^ (instanceId >>> 32));
             result = prime * result + ((name == null) ? 0 : name.hashCode());
             return result;
         }
@@ -124,8 +117,6 @@ public class ByteArrayTemplateLoader implements TemplateLoader {
             if (getClass() != obj.getClass())
                 return false;
             ByteArrayTemplateSource other = (ByteArrayTemplateSource) obj;
-            if (instanceId != other.instanceId)
-                return false;
             if (name == null) {
                 if (other.name != null)
                     return false;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/708097f7/src/main/java/freemarker/cache/StringTemplateLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/cache/StringTemplateLoader.java b/src/main/java/freemarker/cache/StringTemplateLoader.java
index 3f348b0..94e1af3 100644
--- a/src/main/java/freemarker/cache/StringTemplateLoader.java
+++ b/src/main/java/freemarker/cache/StringTemplateLoader.java
@@ -23,7 +23,6 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
 
 import freemarker.template.utility.StringUtil;
 
@@ -62,9 +61,6 @@ import freemarker.template.utility.StringUtil;
  */
 public class StringTemplateLoader implements TemplateLoader {
     
-    private static final AtomicLong INSTANCE_COUNTER = new AtomicLong();
-    
-    private final long instanceId = INSTANCE_COUNTER.incrementAndGet();
     private final Map<String, StringTemplateSource> templates = new HashMap<String,
StringTemplateSource>();
     
     /**
@@ -102,7 +98,7 @@ public class StringTemplateLoader implements TemplateLoader {
      * terms of <tt>System.currentTimeMillis()</tt>
      */
     public void putTemplate(String name, String templateSource, long lastModified) {
-        templates.put(name, new StringTemplateSource(instanceId, name, templateSource, lastModified));
+        templates.put(name, new StringTemplateSource(name, templateSource, lastModified));
     }
     
     /**
@@ -137,13 +133,11 @@ public class StringTemplateLoader implements TemplateLoader {
     }
     
     private static class StringTemplateSource {
-        private final long instanceId;
         private final String name;
         private final String source;
         private final long lastModified;
         
-        StringTemplateSource(long instanceId, String name, String source, long lastModified)
{
-            this.instanceId = instanceId;
+        StringTemplateSource(String name, String source, long lastModified) {
             if (name == null) {
                 throw new IllegalArgumentException("name == null");
             }
@@ -162,7 +156,6 @@ public class StringTemplateLoader implements TemplateLoader {
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result + (int) (instanceId ^ (instanceId >>> 32));
             result = prime * result + ((name == null) ? 0 : name.hashCode());
             return result;
         }
@@ -176,8 +169,6 @@ public class StringTemplateLoader implements TemplateLoader {
             if (getClass() != obj.getClass())
                 return false;
             StringTemplateSource other = (StringTemplateSource) obj;
-            if (instanceId != other.instanceId)
-                return false;
             if (name == null) {
                 if (other.name != null)
                     return false;
@@ -186,6 +177,7 @@ public class StringTemplateLoader implements TemplateLoader {
             return true;
         }
 
+
         @Override
         public String toString() {
             return name;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/708097f7/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 1903d0c..9be62fd 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -26875,15 +26875,6 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
             </listitem>
 
             <listitem>
-              <para>Fixed problem in <literal>StringTemplateLoader</literal>
-              and <literal>ByteArrayTemplateLoader</literal>, which, in some
-              fairly unlikely setups, could confuse the template cache if you
-              are using multiple template loaders of the same class (via
-              <literal>MultiTemplateLoader</literal>) with clashing template
-              names.</para>
-            </listitem>
-
-            <listitem>
               <para>Various smaller code cleanups.</para>
             </listitem>
           </itemizedlist>


Mime
View raw message