When using a variable whose value ends with a colon, that colon is removed when the variable is evaluated.
For example, I have a property file.
I want to use that variable to configure my logging. Example is abbreviated to highlight the usage.
<configuration>
<property resource="my.properties"/>
<appender>
<file>${root}/out.log</file>
</appender>
</configuration>
This produces the following log output in the default logs.
Will use the pattern C/out.log for the active file
Test case to prove the issue. Using NodeToStringTransformerTest as a base.
@Before
public void setUp() {
propertyContainer0.putProperty("root", "C:");
}
@Test
public void trailingColon() throws ScanException {
String input = "${root}";
Node node = makeNode(input);
NodeToStringTransformer nodeToStringTransformer = new NodeToStringTransformer(node, propertyContainer0);
assertEquals("C:", nodeToStringTransformer.transform());
}
Test failure output.
expected:<C[:]> but was:<C[]>
The workaround is easy enough: don't let properties end in a colon. Looks bad, but works.
<configuration>
<property resource="fix.properties"/>
<appender>
<file>${root}out.log</file>
</appender>
</configuration>
However, this isn't always possible. My application has a ${root} property that is assumed to be the drive/network path only, and all application paths include a leading directory slash. I can create a separate property, but having two different properties that look similar but are used in two different places is bad for maintenance.
|