diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java index af9bdd3d4..0b9c1641f 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java @@ -103,22 +103,6 @@ public class OgnlUtil { enableExpressionCache = BooleanUtils.toBoolean(cache); } - /** - * @deprecated since 6.4.0, changing maximum cache size after initialisation is not necessary. - */ - @Deprecated - protected void setExpressionCacheMaxSize(String maxSize) { - expressionCache.setEvictionLimit(Integer.parseInt(maxSize)); - } - - /** - * @deprecated since 6.4.0, changing maximum cache size after initialisation is not necessary. - */ - @Deprecated - protected void setBeanInfoCacheMaxSize(String maxSize) { - beanInfoCache.setEvictionLimit(Integer.parseInt(maxSize)); - } - @Inject(value = StrutsConstants.STRUTS_OGNL_ENABLE_EVAL_EXPRESSION, required = false) protected void setEnableEvalExpression(String evalExpression) { this.enableEvalExpression = BooleanUtils.toBoolean(evalExpression); diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java index 255677d00..0d96337da 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java @@ -181,9 +181,7 @@ public class OgnlUtilTest extends XWorkTestCase { public void testLRUCacheEnabledMaxSize() throws OgnlException { // Force usage of LRU cache factories for the OgnlUtil instance - this.ognlUtil = generateOgnlUtilInstanceWithDefaultLRUCacheFactories(); - ognlUtil.setEnableExpressionCache("true"); - ognlUtil.setExpressionCacheMaxSize("1"); + this.ognlUtil = generateOgnlUtilInstanceWithDefaultLRUCacheFactories(1, 25); Object expr0 = ognlUtil.compile("test"); Object expr2 = ognlUtil.compile("test"); assertSame(expr0, expr2); @@ -410,8 +408,7 @@ public class OgnlUtilTest extends XWorkTestCase { public void testBeanInfoLRUCacheLimits() throws IntrospectionException { // Force usage of LRU cache factories for the OgnlUtil instance - this.ognlUtil = generateOgnlUtilInstanceWithDefaultLRUCacheFactories(); - ognlUtil.setBeanInfoCacheMaxSize("1"); + this.ognlUtil = generateOgnlUtilInstanceWithDefaultLRUCacheFactories(25, 1); final TestBean1 testBean1 = new TestBean1(); final TestBean2 testBean2 = new TestBean2(); // Test that the BeanInfo cache is functioning as expected. @@ -434,7 +431,6 @@ public class OgnlUtilTest extends XWorkTestCase { // LRU cache should not contain TestBean1 beaninfo anymore. A new entry should exist in the cache. Object beanInfo1_4 = ognlUtil.getBeanInfo(testBean1); assertNotSame("BeanInfo dropped from LRU cache is the same as newly added ?", beanInfo1_1, beanInfo1_4); - ognlUtil.setBeanInfoCacheMaxSize(String.valueOf(Integer.MAX_VALUE)); } public void testClearRuntimeCache() { @@ -1648,16 +1644,20 @@ public class OgnlUtilTest extends XWorkTestCase { assertThrows(OgnlException.class, () -> ognlUtil.getValue(vulnerableExpr, ognlUtil.createDefaultContext(null), null)); } + private OgnlUtil generateOgnlUtilInstanceWithDefaultLRUCacheFactories() { + return generateOgnlUtilInstanceWithDefaultLRUCacheFactories(25, 25); + } + /** * Generate a new OgnlUtil instance (not configured by the {@link ContainerBuilder}) that can be used for * basic tests, with its Expression and BeanInfo factories set to LRU mode. * * @return OgnlUtil instance with LRU enabled Expression and BeanInfo factories */ - private OgnlUtil generateOgnlUtilInstanceWithDefaultLRUCacheFactories() { + private OgnlUtil generateOgnlUtilInstanceWithDefaultLRUCacheFactories(int expressionCacheMaxSize, int beanInfoCacheMaxSize) { final OgnlUtil result; - final DefaultOgnlExpressionCacheFactory expressionFactory = new DefaultOgnlExpressionCacheFactory<>(String.valueOf(25), LRU.toString()); - final DefaultOgnlBeanInfoCacheFactory, BeanInfo> beanInfoFactory = new DefaultOgnlBeanInfoCacheFactory<>(String.valueOf(25), LRU.toString()); + final DefaultOgnlExpressionCacheFactory expressionFactory = new DefaultOgnlExpressionCacheFactory<>(String.valueOf(expressionCacheMaxSize), LRU.toString()); + final DefaultOgnlBeanInfoCacheFactory, BeanInfo> beanInfoFactory = new DefaultOgnlBeanInfoCacheFactory<>(String.valueOf(beanInfoCacheMaxSize), LRU.toString()); result = new OgnlUtil(expressionFactory, beanInfoFactory, new StrutsOgnlGuard()); return result; }