You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fs...@apache.org on 2020/06/26 14:59:00 UTC
[tomcat] 03/03: Use method local counter for recurstion
This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch pr309-recursion
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 7f1b56e587693bb8f7755c972fbac493101c53c8
Author: Felix Schumacher <fs...@apache.org>
AuthorDate: Fri Jun 26 16:58:25 2020 +0200
Use method local counter for recurstion
---
java/org/apache/tomcat/util/IntrospectionUtils.java | 19 +++++++++++--------
.../apache/tomcat/util/TestIntrospectionUtils.java | 7 +++++++
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/tomcat/util/IntrospectionUtils.java b/java/org/apache/tomcat/util/IntrospectionUtils.java
index 17fd47e..08e0cbd 100644
--- a/java/org/apache/tomcat/util/IntrospectionUtils.java
+++ b/java/org/apache/tomcat/util/IntrospectionUtils.java
@@ -34,7 +34,7 @@ public final class IntrospectionUtils {
private static final Log log = LogFactory.getLog(IntrospectionUtils.class);
private static final StringManager sm = StringManager.getManager(IntrospectionUtils.class);
- private static int iterationCount = 0;
+ private static final int MAX_RECURSION = 20;
/**
* Find a method with the right name If found, call the method ( if param is
@@ -286,7 +286,16 @@ public final class IntrospectionUtils {
public static String replaceProperties(String value,
Hashtable<Object,Object> staticProp, PropertySource dynamicProp[],
ClassLoader classLoader) {
+ return replaceProperties(value, staticProp, dynamicProp, classLoader, 0);
+ }
+ private static String replaceProperties(String value,
+ Hashtable<Object,Object> staticProp, PropertySource dynamicProp[],
+ ClassLoader classLoader, int iterationCount) {
+ if (iterationCount >= MAX_RECURSION) {
+ log.warn("System property failed to update and remains [" + value + "]");
+ return value;
+ }
if (value.indexOf('$') < 0) {
return value;
}
@@ -341,13 +350,7 @@ public final class IntrospectionUtils {
return value;
if (log.isDebugEnabled())
log.debug("IntrospectionUtils.replaceProperties iter on: " + newval);
- iterationCount++;
- if (iterationCount <20)
- newval = replaceProperties(newval, staticProp, dynamicProp, classLoader);
- else
- log.warn("System property failed to update and remains [" + newval + "]");
- iterationCount--;
- return newval;
+ return replaceProperties(newval, staticProp, dynamicProp, classLoader, iterationCount + 1);
}
private static String getProperty(String name, Hashtable<Object, Object> staticProp,
diff --git a/test/org/apache/tomcat/util/TestIntrospectionUtils.java b/test/org/apache/tomcat/util/TestIntrospectionUtils.java
index ed9fe39..981db4b 100644
--- a/test/org/apache/tomcat/util/TestIntrospectionUtils.java
+++ b/test/org/apache/tomcat/util/TestIntrospectionUtils.java
@@ -112,6 +112,13 @@ public class TestIntrospectionUtils {
StandardContext.class, "com.example.Other"));
}
+ @Test
+ public void testReplacePropertiesRecursive() {
+ Properties properties = new Properties();
+ properties.put("replaceMe", "x${replaceMe}");
+ Assert.assertEquals("xxxxxxxxxxxxxxxxxxxx${replaceMe}",
+ IntrospectionUtils.replaceProperties("${replaceMe}", properties, null, null));
+ }
@Test
public void testReplaceProperties() {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org