-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-3829 S2629 should not report when log level is enabled (#4877)
- Loading branch information
1 parent
e3a2872
commit d5abe0c
Showing
5 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S2629.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S2629", | ||
"hasTruePositives": true, | ||
"falseNegatives": 58, | ||
"falseNegatives": 60, | ||
"falsePositives": 0 | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
java-checks-test-sources/default/src/main/java/checks/LazyArgEvaluationCheckSampleFPs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package checks; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
class FalsePositivesFromTheCommunity { | ||
|
||
private static final Marker myMarker = MarkerFactory.getMarker("MY_MARKER"); | ||
private static final Logger logger = LoggerFactory.getLogger(FalsePositivesFromTheCommunity.class); | ||
|
||
Object doSomething() { | ||
return null; | ||
} | ||
|
||
// https://community.sonarsource.com/t/false-positive-on-java-s2629/42091 | ||
void foo() { | ||
|
||
logger.debug(myMarker, "message1: {}.", doSomething()); // Compliant - because we don't care about small performance loss in exceptional paths | ||
|
||
if (logger.isDebugEnabled(myMarker)) { | ||
logger.debug(myMarker, "message2: {}.", doSomething() + "yolo"); // Compliant as method(s) invoked conditionally - WAS FP due to missing MARKER param handling | ||
logger.debug(myMarker, "message2a: {}.", doSomething()); // Compliant | ||
} | ||
} | ||
|
||
// https://community.sonarsource.com/t/s2629-despite-using-isinfoenabled/120810 | ||
void foo2() { | ||
|
||
logger.debug(myMarker, "message3: {}.", doSomething()); // Compliant - because we don't care about small performance loss in exceptional paths | ||
logger.debug(myMarker, "message4: {}.", doSomething() + "yolo"); // Noncompliant {{Invoke method(s) only conditionally. Use the built-in formatting to construct this argument.}} | ||
|
||
// this return makes the later debug statements in this method compliant | ||
if (!logger.isDebugEnabled(myMarker)) { | ||
return; | ||
} | ||
logger.debug(myMarker, "message4: {}.", doSomething() + "yolo"); // Compliant as method(s) invoked conditionally - IS FP | ||
logger.debug(myMarker, "message4a: {}.", doSomething()); // Compliant | ||
} | ||
|
||
void fooBar() { | ||
|
||
// test without return statement | ||
logger.debug(myMarker, "message3: {}.", doSomething()); // Compliant - because we don't care about small performance loss in exceptional paths | ||
logger.debug(myMarker, "message4: {}.", doSomething() + "yolo"); // Noncompliant {{Invoke method(s) only conditionally. Use the built-in formatting to construct this argument.}} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters