So I misunderstood the usage of `setEnableSubstitutionInVariables
<https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html#setEnableSubstitutionInVariables-boolean->`
and `setDisableSubstitutionInValues
<https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html#setDisableSubstitutionInValues-boolean->`.

In my case, it's substitution in values that should be disabled.

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).setDisableSubstitutionInValues(true);
  String res = sub.replace("my template ${cycle}");
  }
}

works fine

On Fri, Nov 4, 2022 at 12:12 AM Cyril de Catheu <cy...@startree.ai> wrote:

> Hello,
>
> I'm trying to use StringSubstitutor. Substitution in variables (recursive
> substitution) is disabled.
> When I run with a variable cycle, I don't expect an infinite loop because
> recursive substitution is disabled. But I still get the exception:
> java.lang.IllegalStateException: Infinite loop in property interpolation
> of my template ${cycle}: cycle.
>
> See example code below.
>
> import java.util.Map;
> import org.apache.commons.text.StringSubstitutor;
>
> public class TestCycles {
>
>   public static void main(String[] args) {
>     final Map<String, Object> cycleMap = Map.of("cycle", "${cycle}");
>     final StringSubstitutor sub = new StringSubstitutor(cycleMap)
>         .setEnableSubstitutionInVariables(false);
>       String res =  sub.replace("my template ${cycle}");
>   }
> }
>
>
> Is this the expected behavior, or do you think this should be fixed?
>
> Thanks.
>
> --
>
> [image: StarTree] <https://startree.ai>
> Cyril de Catheu
> Software Engineer
> +33 (684) 829-908 <+33+(684)+829-908>
> Follow us: [image: RSS] <https://www.startree.ai/blogs>[image: LinkedIn]
> <https://www.linkedin.com/company/startreedata/>[image: Twitter]
> <https://twitter.com/startreedata>[image: Slack] 
> <https://stree.ai/slack>[image:
> YouTube] <https://youtube.com/StarTreeData>
>
> [image: Try StarTree Cloud Today]
> <https://get.startree.ai/startree-cloud?utm_campaign=byoc-edition-of-startree-cloud&utm_source=email&utm_content=startree-employee-email-signatures>
>

Reply via email to