Skip to content

Commit d144ea2

Browse files
committed
Java: Exclude slf4j calls in PrintLnArray as it supports array formatting.
1 parent b226cb6 commit d144ea2

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

change-notes/1.21/analysis-java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| **Query** | **Expected impact** | **Change** |
1111
|----------------------------|------------------------|------------------------------------------------------------------|
12+
| Implicit conversion from array to string (`java/print-array`) | Fewer false positive results | Results in slf4j logging calls are no longer reported as slf4j supports array printing. |
1213

1314
## Changes to QL libraries
1415

java/ql/src/Violations of Best Practice/Undesirable Calls/PrintLnArray.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ predicate arraysToStringArgument(Expr e) {
2727
from Expr arr
2828
where
2929
arr.getType() instanceof Array and
30-
implicitToStringCall(arr)
30+
implicitToStringCall(arr) and
31+
not exists(FormattingCall fmtcall |
32+
// exclude slf4j formatting as it supports array formatting
33+
fmtcall.getAnArgumentToBeFormatted() = arr and fmtcall.getSyntax().isLogger()
34+
)
3135
or
3236
arr.getType().(Array).getComponentType() instanceof Array and
3337
arraysToStringArgument(arr)

java/ql/src/semmle/code/java/StringFormat.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class FmtSyntax extends TFmtSyntax {
8585
or
8686
result = "logger ({}) syntax" and this = TFmtLogger()
8787
}
88+
89+
/** Holds if this syntax is logger ({}) syntax. */
90+
predicate isLogger() { this = TFmtLogger() }
8891
}
8992

9093
/**

0 commit comments

Comments
 (0)