freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject incubator-freemarker git commit: Removed the deprecated BeansWrapper.nullModel setting. So null is always wrapped to null now.
Date Mon, 20 Feb 2017 18:04:41 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 7deda0105 -> d7f2d65bf


Removed the deprecated BeansWrapper.nullModel setting. So null is always wrapped to null now.


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

Branch: refs/heads/3
Commit: d7f2d65bf2f18b23468330be0e5bf5a3ed0899ca
Parents: 7deda01
Author: ddekany <ddekany@apache.org>
Authored: Mon Feb 20 19:04:33 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Mon Feb 20 19:04:33 2017 +0100

----------------------------------------------------------------------
 .../core/model/impl/beans/BeansWrapper.java     | 21 +----
 src/manual/en_US/FM3-CHANGE-LOG.txt             |  1 +
 .../model/impl/DefaultObjectWrapperTest.java    | 83 +++-----------------
 3 files changed, 16 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d7f2d65b/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java b/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java
index 25f80f3..183712c 100644
--- a/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java
+++ b/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java
@@ -173,7 +173,6 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable
{
     // things from buggy user code.
     private volatile boolean writeProtected;
     
-    private TemplateModel nullModel = null;
     private int defaultDateType; // initialized by PropertyAssignments.apply
     private ObjectWrapper outerIdentity = this;
     private boolean methodsShadowItems = true;
@@ -741,21 +740,6 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable
{
     }
     
     /**
-     * Sets the null model. This model is returned from the {@link #wrap(Object)} method
whenever the wrapped object is
-     * {@code null}. It defaults to {@code null}, which is dealt with quite strictly on engine
level, however you can
-     * substitute an arbitrary (perhaps more lenient) model, like an empty string. For proper
working, the
-     * {@code nullModel} should be an {@link AdapterTemplateModel} that returns {@code null}
for
-     * {@link AdapterTemplateModel#getAdaptedObject(Class)}.
-     * 
-     * @deprecated Changing the {@code null} model can cause a lot of confusion; don't do
it.
-     */
-    @Deprecated
-    public void setNullModel(TemplateModel nullModel) {
-        checkModifiable();
-        this.nullModel = nullModel;
-    }
-    
-    /**
      * Returns the version given with {@link #BeansWrapper(Version)}, normalized to the lowest
version where a change
      * has occurred. Thus, this is not necessarily the same version than that was given to
the constructor.
      * 
@@ -778,7 +762,6 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable
{
      * Wraps the object with a template model that is most specific for the object's
      * class. Specifically:
      * <ul>
-     * <li>if the object is null, returns the {@link #setNullModel(TemplateModel) null
model},</li>
      * <li>if the object is a Number returns a {@link NumberModel} for it,</li>
      * <li>if the object is a Date returns a {@link DateModel} for it,</li>
      * <li>if the object is a Boolean returns 
@@ -796,7 +779,7 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable
{
      */
     @Override
     public TemplateModel wrap(Object object) throws TemplateModelException {
-        if (object == null) return nullModel;
+        if (object == null) return null;
         return modelCache.getInstance(object);
     }
     
@@ -962,7 +945,7 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable
{
     private Object tryUnwrapTo(final TemplateModel model, Class<?> targetClass, final
int typeFlags,
             final Map<Object, Object> recursionStops) 
     throws TemplateModelException {
-        if (model == null || model == nullModel) {
+        if (model == null) {
             return null;
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d7f2d65b/src/manual/en_US/FM3-CHANGE-LOG.txt
----------------------------------------------------------------------
diff --git a/src/manual/en_US/FM3-CHANGE-LOG.txt b/src/manual/en_US/FM3-CHANGE-LOG.txt
index 742b80c..9992c17 100644
--- a/src/manual/en_US/FM3-CHANGE-LOG.txt
+++ b/src/manual/en_US/FM3-CHANGE-LOG.txt
@@ -95,6 +95,7 @@ the FreeMarer 3 changelog here:
 - Even for setting values that are class names without following `()` or other argument list,
the INSTANCE field and
   the builder class will be searched now, and used instead of the constructor of the class.
Earlier they weren't for
   backward compatibility.
+- Removed the deprecated BeansWrapper.nullModel setting. So null is always wrapped to null
now.
 - Removed several deprecated methods and constants. Some notes:
   - strict_bean_models configuration setting was removed, as it should be set on the BeansWrapper
itself
   - .template_name now means the same as .current_template_name (it doesn't emulate 2.3 glitches
anymore)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d7f2d65b/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
b/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
index c1fd449..60b993b 100644
--- a/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
+++ b/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
@@ -90,11 +90,6 @@ public class DefaultObjectWrapperTest {
     private final static DefaultObjectWrapper OW300 = new DefaultObjectWrapperBuilder(Configuration.VERSION_3_0_0)
             .build();
 
-    private final static DefaultObjectWrapper OW300NM = new DefaultObjectWrapper(Configuration.VERSION_3_0_0);
-    static {
-        OW300NM.setNullModel(NullModel.INSTANCE);
-    }
-
     private final static DefaultObjectWrapper OW300CA = new DefaultObjectWrapper(Configuration.VERSION_3_0_0);
     static {
         OW300CA.setForceLegacyNonListCollections(false);
@@ -351,15 +346,6 @@ public class DefaultObjectWrapperTest {
         {
             assertTrue(((TemplateHashModel) OW300.wrap(Collections.emptyMap())).isEmpty());
         }
-
-        {
-            final TemplateHashModelEx hash = (TemplateHashModelEx) OW300NM.wrap(testMap);
-            assertSame(NullModel.INSTANCE, hash.get("b"));
-            assertNull(hash.get("e"));
-
-            assertCollectionTMEquals(hash.keys(), "a", "b", "c", "d");
-            assertCollectionTMEquals(hash.values(), 1, null, "C", Collections.singletonList("x"));
-        }
     }
 
     private void assertCollectionTMEquals(TemplateCollectionModel coll, Object... expectedItems)
@@ -442,15 +428,6 @@ public class DefaultObjectWrapperTest {
                 assertThat(e.getMessage(), containsString("no more"));
             }
         }
-
-        {
-            List testList = new ArrayList<>();
-            testList.add(null);
-
-            final TemplateSequenceModel seq = (TemplateSequenceModel) OW300NM.wrap(testList);
-            assertSame(NullModel.INSTANCE, seq.get(0));
-            assertNull(seq.get(1));
-        }
     }
 
     @Test
@@ -479,24 +456,13 @@ public class DefaultObjectWrapperTest {
         {
             final String[] testArray = new String[] { "a", null, "c" };
 
-            {
-                TemplateSequenceModel seq = (TemplateSequenceModel) OW300.wrap(testArray);
-                assertEquals(3, seq.size());
-                assertNull(seq.get(-1));
-                assertEquals("a", ((TemplateScalarModel) seq.get(0)).getAsString());
-                assertNull(seq.get(1));
-                assertEquals("c", ((TemplateScalarModel) seq.get(2)).getAsString());
-                assertNull(seq.get(3));
-            }
-
-            {
-                TemplateSequenceModel seq = (TemplateSequenceModel) OW300NM.wrap(testArray);
-                assertNull(seq.get(-1));
-                assertEquals("a", ((TemplateScalarModel) seq.get(0)).getAsString());
-                assertSame(NullModel.INSTANCE, seq.get(1));
-                assertEquals("c", ((TemplateScalarModel) seq.get(2)).getAsString());
-                assertNull(seq.get(3));
-            }
+            TemplateSequenceModel seq = (TemplateSequenceModel) OW300.wrap(testArray);
+            assertEquals(3, seq.size());
+            assertNull(seq.get(-1));
+            assertEquals("a", ((TemplateScalarModel) seq.get(0)).getAsString());
+            assertNull(seq.get(1));
+            assertEquals("c", ((TemplateScalarModel) seq.get(2)).getAsString());
+            assertNull(seq.get(3));
         }
 
         {
@@ -658,24 +624,12 @@ public class DefaultObjectWrapperTest {
         Set set = new HashSet();
         set.add(null);
 
-        {
-            DefaultObjectWrapper dow = new DefaultObjectWrapper(Configuration.VERSION_3_0_0);
-            dow.setForceLegacyNonListCollections(false);
-            TemplateCollectionModelEx coll = (TemplateCollectionModelEx) dow.wrap(set);
-            assertEquals(1, coll.size());
-            assertFalse(coll.isEmpty());
-            assertNull(coll.iterator().next());
-        }
-
-        {
-            DefaultObjectWrapper dow = new DefaultObjectWrapper(Configuration.VERSION_3_0_0);
-            dow.setForceLegacyNonListCollections(false);
-            dow.setNullModel(NullModel.INSTANCE);
-            TemplateCollectionModelEx coll = (TemplateCollectionModelEx) dow.wrap(set);
-            assertEquals(1, coll.size());
-            assertFalse(coll.isEmpty());
-            assertEquals(NullModel.INSTANCE, coll.iterator().next());
-        }
+        DefaultObjectWrapper dow = new DefaultObjectWrapper(Configuration.VERSION_3_0_0);
+        dow.setForceLegacyNonListCollections(false);
+        TemplateCollectionModelEx coll = (TemplateCollectionModelEx) dow.wrap(set);
+        assertEquals(1, coll.size());
+        assertFalse(coll.isEmpty());
+        assertNull(coll.iterator().next());
     }
 
     @Test
@@ -870,17 +824,6 @@ public class DefaultObjectWrapperTest {
         }
 
     }
-
-    private static final class NullModel implements TemplateModel, AdapterTemplateModel {
-
-        final static NullModel INSTANCE = new NullModel();
-
-        @Override
-        public Object getAdaptedObject(Class hint) {
-            return null;
-        }
-
-    }
     
     private static class Tupple<E1, E2> {
         


Mime
View raw message