From f0083ab9bd4563298ef2b5abfc37b4e75f469903 Mon Sep 17 00:00:00 2001 From: Dorian Burihabwa Date: Mon, 16 Dec 2024 17:57:32 +0100 Subject: [PATCH] Modify rule S3457: Description acknowledges intentionality (SONARJAVA-5042) --- rules/S3457/java/rule.adoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rules/S3457/java/rule.adoc b/rules/S3457/java/rule.adoc index 677d8ab6f64..3450e411974 100644 --- a/rules/S3457/java/rule.adoc +++ b/rules/S3457/java/rule.adoc @@ -16,6 +16,9 @@ This rule checks whether every format string specifier can be correctly matched * https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html#formatted(java.lang.Object...)[`java.lang.String#formatted`] (since Java 15) * logging methods of https://www.slf4j.org/api/org/slf4j/Logger.html[`org.slf4j.Logger`], https://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html[`java.util.logging.Logger`], https://logging.apache.org/log4j/2.x/javadoc/log4j-api/org/apache/logging/log4j/Logger.html[`org.apache.logging.log4j.Logger`]. +Note that, a developer deliberately choosing to use a less portable format specifier, to have a byte-consistent output across platforms for instance, might trigger the rule in an inappropriate case. +However, as a principle, developers should be intentional in their choice of format specifiers. + == How to fix it A `printf-`-style format string is a string that contains placeholders, which are replaced by values when the string is printed or logged. Mismatch in the format specifiers and the arguments provided can lead to incorrect strings being created.