You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/08/25 23:38:14 UTC

[1/6] incubator-freemarker git commit: Error message fix for ?chunk

Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 05dc3856c -> a4a406a1d


Error message fix for ?chunk


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

Branch: refs/heads/2.3-gae
Commit: 0213afa5f5d154db1bde5c1d74d2d206eff14877
Parents: 05dc385
Author: ddekany <dd...@apache.org>
Authored: Fri Aug 25 23:48:18 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Fri Aug 25 23:48:18 2017 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltInsForSequences.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0213afa5/src/main/java/freemarker/core/BuiltInsForSequences.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInsForSequences.java b/src/main/java/freemarker/core/BuiltInsForSequences.java
index 609f53e..eca5fec 100644
--- a/src/main/java/freemarker/core/BuiltInsForSequences.java
+++ b/src/main/java/freemarker/core/BuiltInsForSequences.java
@@ -64,6 +64,9 @@ class BuiltInsForSequences {
             public Object exec(List args) throws TemplateModelException {
                 checkMethodArgCount(args, 1, 2);
                 int chunkSize = getNumberMethodArg(args, 0).intValue();
+                if (chunkSize < 1) {
+                    throw new _TemplateModelException("The 1st argument to ?", key, " (...) must be at least 1.");
+                }
                 
                 return new ChunkedSequence(
                         tsm,
@@ -85,9 +88,6 @@ class BuiltInsForSequences {
             private ChunkedSequence(
                     TemplateSequenceModel wrappedTsm, int chunkSize, TemplateModel fillerItem)
                     throws TemplateModelException {
-                if (chunkSize < 1) {
-                    throw new _TemplateModelException("The 1st argument to ?', key, ' (...) must be at least 1.");
-                }
                 this.wrappedTsm = wrappedTsm;
                 this.chunkSize = chunkSize;
                 this.fillerItem = fillerItem;


[3/6] incubator-freemarker git commit: Allowed Iterable constructor parameter for SimpleCollection

Posted by dd...@apache.org.
Allowed Iterable constructor parameter for SimpleCollection


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

Branch: refs/heads/2.3-gae
Commit: 3531b06e9e9f1cf730470d886ade505003f31cd9
Parents: e395401
Author: ddekany <dd...@apache.org>
Authored: Sat Aug 26 00:28:02 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sat Aug 26 00:28:02 2017 +0200

----------------------------------------------------------------------
 .../freemarker/template/SimpleCollection.java   | 23 ++++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/3531b06e/src/main/java/freemarker/template/SimpleCollection.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/SimpleCollection.java b/src/main/java/freemarker/template/SimpleCollection.java
index aa67ef1..b29c110 100644
--- a/src/main/java/freemarker/template/SimpleCollection.java
+++ b/src/main/java/freemarker/template/SimpleCollection.java
@@ -43,7 +43,7 @@ implements TemplateCollectionModel, Serializable {
     
     private boolean iteratorOwned;
     private final Iterator iterator;
-    private final Collection collection;
+    private final Iterable iterable;
 
     /**
      * @deprecated Use {@link #SimpleCollection(Iterator, ObjectWrapper)}
@@ -51,27 +51,32 @@ implements TemplateCollectionModel, Serializable {
     @Deprecated
     public SimpleCollection(Iterator iterator) {
         this.iterator = iterator;
-        collection = null;
+        iterable = null;
     }
 
     /**
-     * @deprecated Use {@link #SimpleCollection(Collection, ObjectWrapper)}
+     * @param iterable Note that this was a {@link Collection} before 2.3.27, not an {@link Iterable}
+     *
+     * @deprecated Use {@link #SimpleCollection(Iterable, ObjectWrapper)}
      */
     @Deprecated
-    public SimpleCollection(Collection collection) {
-        this.collection = collection;
+    public SimpleCollection(Iterable iterable) {
+        this.iterable = iterable;
         iterator = null;
     }
 
     public SimpleCollection(Iterator iterator, ObjectWrapper wrapper) {
         super(wrapper);
         this.iterator = iterator;
-        collection = null;
+        iterable = null;
     }
 
-    public SimpleCollection(Collection collection, ObjectWrapper wrapper) {
+    /**
+     * @param iterable Note that this was a {@link Collection} before 2.3.27, not an {@link Iterable}
+     */
+    public SimpleCollection(Iterable iterable, ObjectWrapper wrapper) {
         super(wrapper);
-        this.collection = collection;
+        this.iterable = iterable;
         iterator = null;
     }
 
@@ -87,7 +92,7 @@ implements TemplateCollectionModel, Serializable {
     public TemplateModelIterator iterator() {
         return iterator != null
                 ? new SimpleTemplateModelIterator(iterator, false)
-                : new SimpleTemplateModelIterator(collection.iterator(), true);
+                : new SimpleTemplateModelIterator(iterable.iterator(), true);
     }
     
     /**


[5/6] incubator-freemarker git commit: (Version history fixes)

Posted by dd...@apache.org.
(Version history fixes)


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

Branch: refs/heads/2.3-gae
Commit: ce4b9e4a0e8d4169a3225fd293afd4692f1554de
Parents: 09821f9
Author: ddekany <dd...@apache.org>
Authored: Sat Aug 26 00:28:46 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sat Aug 26 00:28:46 2017 +0200

----------------------------------------------------------------------
 src/manual/en_US/book.xml | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce4b9e4a/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 03c42b0..4961955 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -26917,7 +26917,7 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
               <literal>&amp;&amp;</literal> (logical <quote>and</quote>)
               operator: <literal>\and</literal> and
               <literal>&amp;amp;&amp;amp;</literal>. These are to work around
-              issues in applications where the template must be a valid XML
+              issues in applications where the template must be valid XML
               (<literal>&amp;&amp;</literal> is not valid XML/HTML, at most
               places), or where the template entered is stored after XML or
               HTML escaping. Note that lonely <literal>&amp;amp;</literal>,
@@ -26998,9 +26998,8 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
               <para><literal>Constants.EMPTY_HASH</literal> and
               <literal>GeneralPurposeNothing</literal> (the value of
               <literal>missingVar!</literal>) now implements
-              <literal>TemplateHashModelEx2</literal>, so it can be listed
-              with <literal>&lt;#list ... as k, v&gt;</literal>. Earlier they
-              were only a <literal>TemplateHashModelEx</literal>-s.</para>
+              <literal>TemplateHashModelEx2</literal>. Earlier they were only
+              a <literal>TemplateHashModelEx</literal>-s.</para>
             </listitem>
 
             <listitem>


[6/6] incubator-freemarker git commit: Bug fixed: BeansWrapper and DefaultObjectWrapper, starting from Java 8, when the same JavaBeans property has both non-indexed read method (like String[] getFoo()) and indexed read method (like String getFoo(int inde

Posted by dd...@apache.org.
Bug fixed: BeansWrapper and DefaultObjectWrapper, starting from Java 8, when the same JavaBeans property has both non-indexed read method (like String[] getFoo()) and indexed read method (like String getFoo(int index)), has mistakenly used the indexed read method to access the property. This is a problem because then the array size was unknown, and thus the property has suddenly become unlistable on Java 8. To enable the fix (where it will use the non-indexed read method), you have to increase the value of the incompatibleImprovements constructor argument of the used DefaultObjectWrapper or BeansWrapper to 2.3.27. Note that if you leave the object_wrapper setting of the Configuration on its default, it's enough to increase the incompatibleImprovements setting of the Configuration to 2.3.27, as that's inherited by the default object_wrapper. Note that this bug haven't surfaced before Java 8, as then java.beans.Inrospector has only exposed the non-indexed method when both kind of read 
 method was present.


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

Branch: refs/heads/2.3-gae
Commit: a4a406a1d2e7a994ea589a9e6efe5d7575f69da4
Parents: ce4b9e4
Author: ddekany <dd...@apache.org>
Authored: Sat Aug 26 01:37:32 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sat Aug 26 01:37:32 2017 +0200

----------------------------------------------------------------------
 .../java/freemarker/ext/beans/BeanModel.java    | 16 ++++--
 .../java/freemarker/ext/beans/BeansWrapper.java | 14 ++++-
 .../freemarker/ext/beans/SimpleMethodModel.java | 21 ++++---
 .../java/freemarker/template/Configuration.java | 11 +++-
 .../java/freemarker/template/_TemplateAPI.java  |  1 +
 src/manual/en_US/book.xml                       | 27 +++++++++
 .../ext/beans/BeansWrapperMiscTest.java         | 58 +++++++++++++++++++-
 .../template/DefaultObjectWrapperTest.java      |  2 +-
 8 files changed, 134 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/main/java/freemarker/ext/beans/BeanModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/beans/BeanModel.java b/src/main/java/freemarker/ext/beans/BeanModel.java
index 8ec19ea..312ec98 100644
--- a/src/main/java/freemarker/ext/beans/BeanModel.java
+++ b/src/main/java/freemarker/ext/beans/BeanModel.java
@@ -50,6 +50,7 @@ import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateModelIterator;
 import freemarker.template.TemplateModelWithAPISupport;
 import freemarker.template.TemplateScalarModel;
+import freemarker.template._TemplateAPI;
 import freemarker.template.utility.StringUtil;
 
 /**
@@ -219,10 +220,17 @@ implements
 
         TemplateModel resultModel = UNKNOWN;
         if (desc instanceof IndexedPropertyDescriptor) {
-            Method readMethod = ((IndexedPropertyDescriptor) desc).getIndexedReadMethod(); 
-            resultModel = cachedModel = 
-                new SimpleMethodModel(object, readMethod, 
-                        ClassIntrospector.getArgTypes(classInfo, readMethod), wrapper);
+            IndexedPropertyDescriptor pd = (IndexedPropertyDescriptor) desc;
+            if (wrapper.getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_27
+                    && pd.getReadMethod() != null) {
+                resultModel = wrapper.invokeMethod(object, pd.getReadMethod(), null);
+                // cachedModel remains null, as we don't cache these
+            } else {
+                Method readMethod = pd.getIndexedReadMethod(); 
+                resultModel = cachedModel = 
+                    new SimpleMethodModel(object, readMethod, 
+                            ClassIntrospector.getArgTypes(classInfo, readMethod), wrapper);
+            }
         } else if (desc instanceof PropertyDescriptor) {
             PropertyDescriptor pd = (PropertyDescriptor) desc;
             resultModel = wrapper.invokeMethod(object, pd.getReadMethod(), null);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/main/java/freemarker/ext/beans/BeansWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/beans/BeansWrapper.java b/src/main/java/freemarker/ext/beans/BeansWrapper.java
index f108ad6..ea9158d 100644
--- a/src/main/java/freemarker/ext/beans/BeansWrapper.java
+++ b/src/main/java/freemarker/ext/beans/BeansWrapper.java
@@ -19,6 +19,7 @@
 
 package freemarker.ext.beans;
 
+import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Array;
@@ -247,6 +248,16 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable {
      *       {@code true}. Thus, Java 8 default methods (and the bean properties they define) are exposed, despite that
      *       {@link java.beans.Introspector} (the official JavaBeans introspector) ignores them, at least as of Java 8. 
      *     </li>  
+     *     <li>
+     *       <p>2.3.27 (or higher):
+     *       If the same JavaBean property has both an indexed property reader (like {@code String getFoo(int)}) and
+     *       a non-indexed property reader (like {@code String[] getFoo()}), and {@link Introspector} exposes both
+     *       (which apparently only happens since Java 8), we will use the non-indexed property reader method, while
+     *       before this improvement we have used the indexed property method. When using the indexed property reader,
+     *       FreeMarker doesn't know the size of the array, so the value becomes unlistable. Before Java 8 this problem
+     *       haven't surfaced, as {@link Introspector} has only exposed the non-indexed property reader method when both
+     *       kind of read method was present. So this can be seen as a Java 8 compatibility fix.  
+     *     </li>  
      *   </ul>
      *   
      *   <p>Note that the version will be normalized to the lowest version where the same incompatible
@@ -844,7 +855,8 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable {
         if (incompatibleImprovements.intValue() < _TemplateAPI.VERSION_INT_2_3_0) {
             throw new IllegalArgumentException("Version must be at least 2.3.0.");
         }
-        return incompatibleImprovements.intValue() >= _TemplateAPI.VERSION_INT_2_3_26 ? Configuration.VERSION_2_3_26
+        return incompatibleImprovements.intValue() >= _TemplateAPI.VERSION_INT_2_3_27 ? Configuration.VERSION_2_3_27
+                : incompatibleImprovements.intValue() == _TemplateAPI.VERSION_INT_2_3_26 ? Configuration.VERSION_2_3_26
                 : is2324Bugfixed(incompatibleImprovements) ? Configuration.VERSION_2_3_24
                 : is2321Bugfixed(incompatibleImprovements) ? Configuration.VERSION_2_3_21
                 : Configuration.VERSION_2_3_0;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/main/java/freemarker/ext/beans/SimpleMethodModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/beans/SimpleMethodModel.java b/src/main/java/freemarker/ext/beans/SimpleMethodModel.java
index e7e1ae1..9b8150b 100644
--- a/src/main/java/freemarker/ext/beans/SimpleMethodModel.java
+++ b/src/main/java/freemarker/ext/beans/SimpleMethodModel.java
@@ -24,13 +24,16 @@ import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.List;
 
+import freemarker.core._DelayedFTLTypeDescription;
+import freemarker.core._DelayedToString;
+import freemarker.core._ErrorDescriptionBuilder;
+import freemarker.core._TemplateModelException;
 import freemarker.core._UnexpectedTypeErrorExplainerTemplateModel;
 import freemarker.template.SimpleNumber;
 import freemarker.template.TemplateMethodModelEx;
 import freemarker.template.TemplateModel;
 import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateSequenceModel;
-import freemarker.template.utility.ClassUtil;
 
 /**
  * A class that will wrap a reflected method call into a
@@ -81,13 +84,15 @@ public final class SimpleMethodModel extends SimpleMethod
     }
 
     public int size() throws TemplateModelException {
-        throw new TemplateModelException(
-                "Getting the number of items or enumerating the items is not supported on this "
-                + ClassUtil.getFTLTypeDescription(this) + " value.\n"
-                + "("
-                + "Hint 1: Maybe you wanted to call this method first and then do something with its return value. "
-                + "Hint 2: Getting items by intex possibly works, hence it's a \"+sequence\"."
-                + ")");
+        throw new _TemplateModelException(
+                new _ErrorDescriptionBuilder(
+                "Getting the number of items or listing the items is not supported on this ",
+                new _DelayedFTLTypeDescription(this), " value, because this value wraps the following Java method, "
+                + "not a real listable value: ", new _DelayedToString(getMember()))
+                .tips(
+                        "Maybe you should to call this method first and then do something with its return value.",
+                        "obj.someMethod(i) and obj.someMethod[i] does the same for this method, hence it's a "
+                        + "\"+sequence\"."));
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/main/java/freemarker/template/Configuration.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java
index efa14ee..8b14da6 100644
--- a/src/main/java/freemarker/template/Configuration.java
+++ b/src/main/java/freemarker/template/Configuration.java
@@ -414,7 +414,7 @@ public class Configuration extends Configurable implements Cloneable, ParserConf
     /** FreeMarker version 2.3.26 (an {@link #Configuration(Version) incompatible improvements break-point}) */
     public static final Version VERSION_2_3_26 = new Version(2, 3, 26);
 
-    /** FreeMarker version 2.3.26 (an {@link #Configuration(Version) incompatible improvements break-point}) */
+    /** FreeMarker version 2.3.27 (an {@link #Configuration(Version) incompatible improvements break-point}) */
     public static final Version VERSION_2_3_27 = new Version(2, 3, 27);
     
     /** The default of {@link #getIncompatibleImprovements()}, currently {@link #VERSION_2_3_0}. */
@@ -833,6 +833,15 @@ public class Configuration extends Configurable implements Cloneable, ParserConf
      *          properties they define); see {@link BeansWrapper#BeansWrapper(Version)}. 
      *     </ul>
      *   </li>
+     *   <li><p>
+     *     2.3.27 (or higher):
+     *     <ul>
+     *       <li><p>
+     *          {@link BeansWrapper} and {@link DefaultObjectWrapper} now prefers the non-indexed JavaBean property
+     *          read method over the indexed read method when Java 8 exposes both;
+     *          see {@link BeansWrapper#BeansWrapper(Version)}. 
+     *     </ul>
+     *   </li>
      * </ul>
      * 
      * @throws IllegalArgumentException

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/main/java/freemarker/template/_TemplateAPI.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/_TemplateAPI.java b/src/main/java/freemarker/template/_TemplateAPI.java
index 22cbc21..62960c8 100644
--- a/src/main/java/freemarker/template/_TemplateAPI.java
+++ b/src/main/java/freemarker/template/_TemplateAPI.java
@@ -48,6 +48,7 @@ public class _TemplateAPI {
     public static final int VERSION_INT_2_3_24 = Configuration.VERSION_2_3_24.intValue();
     public static final int VERSION_INT_2_3_25 = Configuration.VERSION_2_3_25.intValue();
     public static final int VERSION_INT_2_3_26 = Configuration.VERSION_2_3_26.intValue();
+    public static final int VERSION_INT_2_3_27 = Configuration.VERSION_2_3_27.intValue();
     public static final int VERSION_INT_2_4_0 = Version.intValueFor(2, 4, 0);
     
     public static void checkVersionNotNullAndSupported(Version incompatibleImprovements) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 4961955..809822b 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -26965,6 +26965,33 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
             </listitem>
 
             <listitem>
+              <para>Bug fixed: <literal>BeansWrapper</literal> and
+              <literal>DefaultObjectWrapper</literal>, starting from Java 8,
+              when the same JavaBeans property has both non-indexed read
+              method (like <literal>String[] getFoo()</literal>) and indexed
+              read method (like <literal>String getFoo(int index)</literal>),
+              has mistakenly used the indexed read method to access the
+              property. This is a problem because then the array size was
+              unknown, and thus the property has suddenly become unlistable on
+              Java 8. To enable the fix (where it will use the non-indexed
+              read method), you have to increase the value of the
+              <literal>incompatibleImprovements</literal> constructor argument
+              of the used <literal>DefaultObjectWrapper</literal> or
+              <literal>BeansWrapper</literal> to 2.3.27. Note that if you
+              leave the <literal>object_wrapper</literal> setting of the
+              <literal>Configuration</literal> on its default, it's enough to
+              increase the <link
+              linkend="pgui_config_incompatible_improvements_how_to_set"><literal>incompatibleImprovements</literal>
+              setting</link> of the <literal>Configuration</literal> to
+              2.3.27, as that's inherited by the default
+              <literal>object_wrapper</literal>. Note that this bug haven't
+              surfaced before Java 8, as then
+              <literal>java.beans.Inrospector</literal> has only exposed the
+              non-indexed method when both kind of read method was
+              present.</para>
+            </listitem>
+
+            <listitem>
               <para>Bug fixed: When the
               <literal>TemplateExceptionHandler</literal> suppresses (i.e.,
               doesn't re-throw) an exception, the <link

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java b/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java
index 697a98c..917b2b3 100644
--- a/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java
+++ b/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java
@@ -19,20 +19,30 @@
 
 package freemarker.ext.beans;
 
+import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.*;
 
+import java.util.Collections;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
+import freemarker.template.Configuration;
 import freemarker.template.TemplateBooleanModel;
 import freemarker.template.TemplateHashModel;
+import freemarker.template.TemplateMethodModelEx;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateScalarModel;
+import freemarker.template.TemplateSequenceModel;
+import freemarker.template.utility.Constants;
 
 @RunWith(JUnit4.class)
 public class BeansWrapperMiscTest {
 
     @Test
-    public void booleans() throws Exception {
+    public void booleansTest() throws Exception {
         final BeansWrapper bw = new BeansWrapper();
 
         assertTrue(((TemplateBooleanModel) bw.wrap(Boolean.TRUE)).getAsBoolean());
@@ -54,4 +64,50 @@ public class BeansWrapperMiscTest {
         assertSame(tm, bw.wrap(Boolean.TRUE));
     }
     
+    @Test
+    public void java8IndexedMethodIssueTest() throws TemplateModelException {
+        {
+            BeansWrapper bw = new BeansWrapper(Configuration.VERSION_2_3_26);
+            TemplateHashModel beanTM = (TemplateHashModel) bw.wrap(new BeanWithBothIndexedAndArrayProperty());
+            TemplateModel fooTM = beanTM.get("foo");
+            assertThat(fooTM, instanceOf(TemplateMethodModelEx.class));
+            assertThat(fooTM, instanceOf(TemplateSequenceModel.class));
+            assertEquals("b",
+                    ((TemplateScalarModel) ((TemplateMethodModelEx) fooTM).exec(
+                            Collections.singletonList(Constants.ONE)))
+                    .getAsString());
+            try {
+                ((TemplateSequenceModel) fooTM).size();
+                fail();
+            } catch (TemplateModelException e) {
+                // Expected
+            }
+        }
+        
+        {
+            BeansWrapper bw = new BeansWrapper(Configuration.VERSION_2_3_27);
+            TemplateHashModel beanTM = (TemplateHashModel) bw.wrap(new BeanWithBothIndexedAndArrayProperty());
+            TemplateModel fooTM = beanTM.get("foo");
+            assertThat(fooTM, not(instanceOf(TemplateMethodModelEx.class)));
+            assertThat(fooTM, instanceOf(TemplateSequenceModel.class));
+            assertEquals("b",
+                    ((TemplateScalarModel) ((TemplateSequenceModel) fooTM).get(1)).getAsString());
+            assertEquals(2, ((TemplateSequenceModel) fooTM).size());
+        }
+    }
+    
+    public static class BeanWithBothIndexedAndArrayProperty {
+        
+        private final static String[] FOO = new String[] { "a", "b" };
+        
+        public String[] getFoo() {
+            return FOO;
+        }
+        
+        public String getFoo(int index) {
+            return FOO[index];
+        }
+        
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a4a406a1/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/template/DefaultObjectWrapperTest.java b/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
index 9a9e283..26bcf9a 100644
--- a/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
+++ b/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
@@ -93,7 +93,7 @@ public class DefaultObjectWrapperTest {
         expected.add(Configuration.VERSION_2_3_24);
         expected.add(Configuration.VERSION_2_3_24); // no non-BC change in 2.3.25
         expected.add(Configuration.VERSION_2_3_26);
-        expected.add(Configuration.VERSION_2_3_26); // no non-BC change in 2.3.27
+        expected.add(Configuration.VERSION_2_3_27);
 
         List<Version> actual = new ArrayList<Version>();
         for (int i = _TemplateAPI.VERSION_INT_2_3_0; i <= Configuration.getVersion().intValue(); i++) {


[2/6] incubator-freemarker git commit: (JavaDoc improvements)

Posted by dd...@apache.org.
(JavaDoc improvements)


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

Branch: refs/heads/2.3-gae
Commit: e395401297b57e9208e4f17bffbb7731bc77b75a
Parents: 0213afa
Author: ddekany <dd...@apache.org>
Authored: Sat Aug 26 00:26:36 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sat Aug 26 00:26:36 2017 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/ext/beans/BeanModel.java       |  2 +-
 .../freemarker/template/TemplateCollectionModel.java    | 12 ++++++++----
 .../freemarker/template/TemplateCollectionModelEx.java  |  4 ++--
 3 files changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3954012/src/main/java/freemarker/ext/beans/BeanModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/beans/BeanModel.java b/src/main/java/freemarker/ext/beans/BeanModel.java
index f9b56c7..8ec19ea 100644
--- a/src/main/java/freemarker/ext/beans/BeanModel.java
+++ b/src/main/java/freemarker/ext/beans/BeanModel.java
@@ -119,7 +119,7 @@ implements
      * matching the key name. If a method or property is found, it's wrapped
      * into {@link freemarker.template.TemplateMethodModelEx} (for a method or
      * indexed property), or evaluated on-the-fly and the return value wrapped
-     * into appropriate model (for a simple property) Models for various
+     * into appropriate model (for a non-indexed property) Models for various
      * properties and methods are cached on a per-class basis, so the costly
      * introspection is performed only once per property or method of a class.
      * (Side-note: this also implies that any class whose method has been called

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3954012/src/main/java/freemarker/template/TemplateCollectionModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/TemplateCollectionModel.java b/src/main/java/freemarker/template/TemplateCollectionModel.java
index f6662af..4bd21f8 100644
--- a/src/main/java/freemarker/template/TemplateCollectionModel.java
+++ b/src/main/java/freemarker/template/TemplateCollectionModel.java
@@ -23,10 +23,14 @@ import java.util.Collection;
 
 /**
  * "collection" template language data type: a collection of values that can be enumerated, but can't be or not meant to
- * be accessed by index or key. As such, this is not a super-interface of {@link TemplateSequenceModel}, and
- * implementations of that interface needn't also implement this interface just because they can. They should though, if
- * enumeration with this interface is significantly faster than enumeration by index. The {@code #list} directive will
- * enumerate using this interface if it's available.
+ * be accessed by index or key, nor the number of elements in it is known. As such, this is very similar to Java's
+ * {@link Iterable} interface (but it predates that interface, hence the unfortunate class name).
+ * 
+ * <p>
+ * Note that this is not a super-interface of {@link TemplateSequenceModel}, and implementations of that interface
+ * needn't also implement this interface just because they can. They should though, if enumeration with this interface
+ * is significantly faster than enumeration by index. The {@code #list} directive will enumerate using this interface if
+ * it's available.
  * 
  * <p>
  * The enumeration should be repeatable if that's possible with reasonable effort, otherwise a second enumeration

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e3954012/src/main/java/freemarker/template/TemplateCollectionModelEx.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/TemplateCollectionModelEx.java b/src/main/java/freemarker/template/TemplateCollectionModelEx.java
index 266c209..f089abf 100644
--- a/src/main/java/freemarker/template/TemplateCollectionModelEx.java
+++ b/src/main/java/freemarker/template/TemplateCollectionModelEx.java
@@ -22,8 +22,8 @@ package freemarker.template;
 import java.util.Collection;
 
 /**
- * "extended collection" template language data type: Adds size/emptiness querybility and "contains" test to
- * {@link TemplateCollectionModel}. The added extra operations is provided by all Java {@link Collection}-s, and this
+ * "collection" template language data type: Adds size/emptiness querybility to
+ * {@link TemplateCollectionModel}. The added extra operations are provided by all Java {@link Collection}-s, and this
  * interface was added to make that accessible for templates too.
  * 
  * @since 2.3.22


[4/6] incubator-freemarker git commit: Added VERSION_2_3_27 to Configuration

Posted by dd...@apache.org.
Added VERSION_2_3_27 to Configuration


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

Branch: refs/heads/2.3-gae
Commit: 09821f96c2703fcaab0bbe739cd527ff6e8ad5da
Parents: 3531b06
Author: ddekany <dd...@apache.org>
Authored: Sat Aug 26 00:28:24 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sat Aug 26 00:28:24 2017 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/template/Configuration.java | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/09821f96/src/main/java/freemarker/template/Configuration.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java
index 5956a39..efa14ee 100644
--- a/src/main/java/freemarker/template/Configuration.java
+++ b/src/main/java/freemarker/template/Configuration.java
@@ -413,6 +413,9 @@ public class Configuration extends Configurable implements Cloneable, ParserConf
 
     /** FreeMarker version 2.3.26 (an {@link #Configuration(Version) incompatible improvements break-point}) */
     public static final Version VERSION_2_3_26 = new Version(2, 3, 26);
+
+    /** FreeMarker version 2.3.26 (an {@link #Configuration(Version) incompatible improvements break-point}) */
+    public static final Version VERSION_2_3_27 = new Version(2, 3, 27);
     
     /** The default of {@link #getIncompatibleImprovements()}, currently {@link #VERSION_2_3_0}. */
     public static final Version DEFAULT_INCOMPATIBLE_IMPROVEMENTS = Configuration.VERSION_2_3_0;