Skip to content

Commit 468a6f2

Browse files
authored
Merge pull request github#11290 from tamasvajk/kotlin-autoboxing
Kotlin: Exclude .kt files from autoboxing query
2 parents 266a087 + 3d21f89 commit 468a6f2

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

java/ql/src/Violations of Best Practice/legacy/AutoBoxing.ql

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,16 @@ predicate rebox(Assignment e, Variable v) {
7272

7373
from Expr e, string conv
7474
where
75-
boxed(e) and conv = "This expression is implicitly boxed."
76-
or
77-
unboxed(e) and conv = "This expression is implicitly unboxed."
78-
or
79-
exists(Variable v | rebox(e, v) |
80-
conv =
81-
"This expression implicitly unboxes, updates, and reboxes the value of '" + v.getName() + "'."
75+
e.getFile().isJavaSourceFile() and
76+
(
77+
boxed(e) and conv = "This expression is implicitly boxed."
78+
or
79+
unboxed(e) and conv = "This expression is implicitly unboxed."
80+
or
81+
exists(Variable v | rebox(e, v) |
82+
conv =
83+
"This expression implicitly unboxes, updates, and reboxes the value of '" + v.getName() +
84+
"'."
85+
)
8286
)
8387
select e, conv

java/ql/test/kotlin/query-tests/AutoBoxing/AutoBoxing.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Violations of Best Practice/legacy/AutoBoxing.ql
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fun foo(x: Int?) {
2+
if (x != null) {
3+
println(x)
4+
}
5+
}

0 commit comments

Comments
 (0)