findbugs-slf4j
findbugs-slf4j copied to clipboard
False positive in SLF4J_PLACE_HOLDER_MISMATCH when a runtime Throwable is passed to a compile time Object version of log.warn
In the case below, we intentionally select an overloaded version of the warn
method that takes a single Object
argument.
The behaviour is different from the other overloads of Logger.warn
(Object... arguments
) or (Throwable t
).
The code is correct, but we receive a false positive.
/**
* Log a message at the WARN level according to the specified format
* and argument.
* <p/>
* <p>This form avoids superfluous object creation when the logger
* is disabled for the WARN level. </p>
*
* @param format the format string
* @param arg the argument
*/
public void warn(String format, Object arg);
/**
* Log a message at the WARN level according to the specified format
* and arguments.
* <p/>
* <p>This form avoids superfluous string concatenation when the logger
* is disabled for the WARN level. However, this variant incurs the hidden
* (and relatively small) cost of creating an <code>Object[]</code> before invoking the method,
* even if this logger is disabled for WARN. The variants taking
* {@link #warn(String, Object) one} and {@link #warn(String, Object, Object) two}
* arguments exist solely in order to avoid this hidden cost.</p>
*
* @param format the format string
* @param arguments a list of 3 or more arguments
*/
public void warn(String format, Object... arguments);
/**
* Log an exception (throwable) at the WARN level with an
* accompanying message.
*
* @param msg the message accompanying the exception
* @param t the exception (throwable) to log
*/
public void warn(String msg, Throwable t);
The first one never checks for the argument being a Throwable, and therefore the code is correct.
Version:
<plugin>
<groupId>jp.skypencil.findbugs.slf4j</groupId>
<artifactId>bug-pattern</artifactId>
<version>1.5.0</version>
</plugin>