Dobias van Buuren created FELIX-5405:
----------------------------------------
Summary: Do not have org.apache.felix.dm.Logger invoke toString()
of message parameters when enabled log level is not high enough
Key: FELIX-5405
URL: https://issues.apache.org/jira/browse/FELIX-5405
Project: Felix
Issue Type: Improvement
Components: Dependency Manager
Affects Versions: org.apache.felix.dependencymanager-r8
Reporter: Dobias van Buuren
My attention was drawn to the following code block when I encountered a NPE at
runtime. In this situation, the Dependency manager wanted to debug log some
class instance, but the class instances' toString() implementation (from a 3rd
party in this case) raised a NPE. While it is arguable why the toString()
implementation was not that robust, it triggered a problem with the logging in
the DM.
{code}
public void debug(String format, Object... params) {
log(LogService.LOG_DEBUG, String.format(format, params));
}
{code}
In the above code block you can see that the String.format(...) is performed
ALWAYS, without checking for the log level being debug.
I suggest deferring the String.format() into the log() method, and only
performing the formatting if we need to write the message to the log.
(PERFORMANCE)
Also it might be wise to perform the String.format() operation in a try catch
block to prevent exceptions during logging that occur when String parameters
need to be created using Object.toString(). (ROBUSTNESS)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)