svn commit: r1339504 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java widget/src/org/ofbiz/widget/screen/HtmlWidget.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1339504 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java widget/src/org/ofbiz/widget/screen/HtmlWidget.java

jacopoc
Author: jacopoc
Date: Thu May 17 07:25:13 2012
New Revision: 1339504

URL: http://svn.apache.org/viewvc?rev=1339504&view=rev
Log:
Based on suggestion from Daniel Dekany (committer/maintainer of the Freemarker's project):

"Since BeansWrapper.getDefaultInstance() returns an instance that is
 shared in the scope of the class-loader that defined the FreeMarker
 classes, and since possibly multiple independently developed
 components in your system use FreeMarker and thus getDefaultInstance
 (and you may don't even know about it), and since the returned
 BeanWrapper can be configured (not read-only), you never know how the
 returned BeanWrapper is configured. So you add a 3rd party component,
 and if you are unlucky, suddenly your other component is broken.
 As of creating new BeansWrapper, be sure you create it only once
 during the application life-cycle and then reuse the same instance, or
 else it will have to rebuild the class introspection cache again and
 again."
 
 I have replaced the usage of the static instance of the BeansWrapper with a newly created object.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java?rev=1339504&r1=1339503&r2=1339504&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java Thu May 17 07:25:13 2012
@@ -76,8 +76,7 @@ public class FreeMarkerWorker {
 
     // use soft references for this so that things from Content records don't kill all of our memory, or maybe not for performance reasons... hmmm, leave to config file...
     public static UtilCache<String, Template> cachedTemplates = UtilCache.createUtilCache("template.ftl.general", 0, 0, false);
-    protected static BeansWrapper defaultOfbizWrapper = BeansWrapper.getDefaultInstance();
-    protected static Configuration defaultOfbizConfig = makeConfiguration(defaultOfbizWrapper);
+    protected static Configuration defaultOfbizConfig = makeConfiguration(new BeansWrapper());
 
     public static Configuration makeConfiguration(BeansWrapper wrapper) {
         Configuration newConfig = new Configuration();

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java?rev=1339504&r1=1339503&r2=1339504&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java Thu May 17 07:25:13 2012
@@ -58,8 +58,7 @@ public class HtmlWidget extends ModelScr
     public static final String module = HtmlWidget.class.getName();
 
     public static UtilCache<String, Template> specialTemplateCache = UtilCache.createUtilCache("widget.screen.template.ftl.general", 0, 0, false);
-    protected static BeansWrapper specialBeansWrapper = new ExtendedWrapper();
-    protected static Configuration specialConfig = FreeMarkerWorker.makeConfiguration(specialBeansWrapper);
+    protected static Configuration specialConfig = FreeMarkerWorker.makeConfiguration((BeansWrapper)new ExtendedWrapper());
 
     // not sure if this is the best way to get FTL to use my fancy MapModel derivative, but should work at least...
     public static class ExtendedWrapper extends BeansWrapper {