差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

java:sonarlint:fixbug:s2275 [2020/08/02 23:58]
tony
java:sonarlint:fixbug:s2275 [2023/06/25 09:48]
行 1: 行 1:
-{{tag>​SonarLint}} +
-====== SonarLint | Printf-style format strings should not lead to unexpected behavior at runtime (java:​S2275) ====== +
-===== Problem ===== +
-這個問題是發生在print、formatter、log4j等API,當你該傳入參數是沒傳入時,就可能會被SonarLint找出來。以我的範例來說,是發生在logger.warn的誤用,這會導致輸出的內容將會是{}:​ +
-<code java> +
-}catch (Exception ex){ +
- logger.warn("​get system property error :​{}",​ex);​ +
- return aDefaultValue;​ +
-+
-</​code>​ +
-===== How to fix? ===== +
-假如你只是要印例外的call stack,把{}拿掉即可:​ +
-<code java> +
-logger.warn("​get system property error",​ex);​ +
-</​code>​ +
-假如你是要印訊息,就直接getMessage:​ +
-<code java> +
-logger.warn("​get system property error :​{}",​ex.getMessage());​ +
-</​code>​ +
-=====    ===== +
----- +
-\\ +
-~~DISQUS~~+