Bug 64398 - New "default values in property value expressions" syntax breaks Log4j2's "property substitution" syntax
Summary: New "default values in property value expressions" syntax breaks Log4j2's "pr...
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.5.54
Hardware: PC FreeBSD
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2020-04-30 07:39 UTC by Frank Erens
Modified: 2020-05-01 16:23 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Frank Erens 2020-04-30 07:39:11 UTC
In Tomcat 8.5.54, the following commit was added:


This uses the syntax ${foo:bar} to mean "If 'foo' is undefined, replace with 'bar'"

Log4j2 has a feature called "property substitution":


For example, ${env:fooConfDir} is replaced with the value of the environment variable "fooConfDir".

Due to the commit in 8.5.54, ${env:fooConfDir} instead now gets replaced with the literal value "fooConfDir" (assuming no variable named "env" is defined).

In our case, we have the following lines in our web.xml (redacted):


As of Tomcat 8.5.54, Log4j fails to find its configuration file with the following error:

ERROR StatusLogger Unable to access file://fooConfDir/foo/log4j2.xml java.net.UnknownHostException: fooConfDir

It appears that the new syntax linked above interferes with Log4j's property substitution.

Recommend changing the "default" syntax to ${foo:-bar} as this is also the syntax used by Log4j: https://logging.apache.org/log4j/2.x/manual/configuration.html#DefaultProperties
Comment 1 Mark Thomas 2020-04-30 08:24:55 UTC
I don't like that the change in default format isn't backwards compatible but given the popularity of log4j2 and that the Tomcat feature is relatively new, I think this is the right thing to do.
Comment 2 Remy Maucherat 2020-04-30 08:42:12 UTC
Ok, this is unfortunate.

Or maybe this feature could be skipped in some cases [with an option, skip by default], like for web.xml and the user descriptors ? To be honest, it is rather bad to do any property replacement at all there as it makes the webapp non portable.

If it is kept, I don't really like ":-" as it's not intuitive, is "::" possible instead ?
Comment 3 Frank Erens 2020-04-30 08:49:11 UTC
${variable:-default} syntax is also used by bash/sh:
Comment 4 Michael Osipov 2020-04-30 08:53:47 UTC
I would also recommend to use :-. This shell/bsah default. Logback uses the same style.
Comment 5 Remy Maucherat 2020-04-30 14:46:04 UTC
Ok for ":-" then. This will be in 10.0-M5, 9.0.35, 8.5.55, 7.0.104.
Comment 6 Frank Erens 2020-04-30 15:14:21 UTC
Thank you for resolving this so quickly!
Comment 7 Christopher Schultz 2020-05-01 16:23:48 UTC
Another vote in favor of ":-"