slf4j expects format strings to prevent unnecessary string concatenation; as a result, these format strings should be constant.
Positive example:
void f(String param) {
...
// BUG: Diagnostic contains: non-constant expression
log.warn("some message param=" + param);
}
Negative example:
void f(String param) {
...
log.warn("some message param {}", param);
}
with extension to the full set of slf4j Logger methods.
I'd be happy to contribute this if appropriate/will set up as a plugin otherwise.
another negative example:
void f(String param) {
...
log.warn("some message param {}" + " for f method", param);
}
Another thing that could be checked is that the number of parameters matches the number of {} expressions in the format string.
If you are willing to use findbugs, all those rules already exist.
Correct. We're actually trying to move away from Findbugs.
On Fri, Mar 17, 2017, 19:12 Matt Nelson notifications@github.com wrote:
If are willing to use findbugs, all those rules already exist.
https://github.com/KengoTODA/findbugs-slf4j
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/google/error-prone/issues/565#issuecomment-287446154,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGOdwQbabwaB_jNUaXPTpkyKCLxpIclYks5rmtr4gaJpZM4MXoLd
.
We've implemented this as a plugin, but happy to contribute it:
https://github.com/palantir/gradle-baseline/blob/develop/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/Slf4jConstantLogMessage.java
Hello, I also developed a Errorprone plugin for SLF4J users, you may check it:
https://github.com/KengoTODA/errorprone-slf4j
Most helpful comment
Another thing that could be checked is that the number of parameters matches the number of
{}expressions in the format string.