Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive in SLF4J_PLACE_HOLDER_MISMATCH when a runtime Throwable is passed to a compile time Object version of log.warn #503

Open
MateuszStefek opened this issue Jul 18, 2024 · 0 comments

Comments

@MateuszStefek
Copy link

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.

image


    /**
     * 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant