SVL Other Notes
This page collects behavioral notes and caveats for the org.apache.juneau.commons.svl resolver that are useful to know when embedding SVL in your own strings.
Escaping
The backslash \ escape character can be used to prevent the resolver from interpreting the SVL
metacharacters $, ,, {, and }. This lets you emit a literal $FOO{...} sequence without having
it resolved:
// Produces the literal text "$S{java.home}" instead of resolving it.
String s = VarResolver.DEFAULT.resolve("\\$S{java.home}");
Escaping is most often needed when the surrounding text legitimately contains currency symbols or brace characters that would otherwise be mistaken for variable syntax.
Recursion and stack safety
Variables are resolved recursively — a resolved value that itself contains variables is resolved again.
This is what makes nesting like $E{X,$S{Y}} work, but it also means a variable that (directly or
indirectly) resolves to a reference to itself will loop.
It is possible to trigger a
StackOverflowError
if your nested variables form a recursive loop — for example, if the environment variable MYPROPERTY
has the value $E{MYPROPERTY}. Avoid self-referential variable definitions.
Efficiency
The resolver is designed to avoid unnecessary work and object allocation:
- Resolving a string that contains no variables is a no-op —
VarResolver.DEFAULT.resolve("foobar")returns the same string reference rather than building a new one. VarResolverinstances are immutable and thread-safe, so a single instance (such asVarResolver.DEFAULT) can be shared across threads and reused indefinitely.- For templates that are resolved repeatedly,
VarResolver.compile(...)returns a reusable VarTemplate that tokenizes the input once, avoiding re-parsing on every resolve.
See also
- Simple Variable Language — the full SVL reference.
- VarResolver.DEFAULT — the reusable default resolver.