Cyril de Catheu created TEXT-223:
------------------------------------
Summary: StringSubstitutor checks for cycles even if recursive
substitution is disabled
Key: TEXT-223
URL: https://issues.apache.org/jira/browse/TEXT-223
Project: Commons Text
Issue Type: Bug
Affects Versions: 1.10.0
Reporter: Cyril de Catheu
**Issue**
StringSubstitutor can perform [recursive variable
replacements|https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html#:~:text=recursive].
If there is a cycle, an IllegalStateException is thrown.
When using StringSubstitutor with recursive substitution disabled, an exception
is still thrown in case of cycles.
**Expected behavior: **
No exception should be thrown. There is no cycle because the replacement is
not recursive.
**How to reproduce:**
```
import java.util.Map;
import org.apache.commons.text.StringSubstitutor;
public class TestCycles {
public static void main(String[] args) {
Map<String, Object> cycleMap = Map.of("cycle", "${cycle}");
StringSubstitutor sub = new
StringSubstitutor(cycleMap).setEnableSubstitutionInVariables(false);
String res = sub.replace("my template ${cycle}");
}
}
```
Will throw
```
java.lang.IllegalStateException: Infinite loop in property interpolation of my
template ${cycle}: cycle.
```
--
This message was sent by Atlassian Jira
(v8.20.10#820010)