diff --git a/java/ql/src/Violations of Best Practice/legacy/AutoBoxing.ql b/java/ql/src/Violations of Best Practice/legacy/AutoBoxing.ql index b80f86cd810..c6d8d796309 100644 --- a/java/ql/src/Violations of Best Practice/legacy/AutoBoxing.ql +++ b/java/ql/src/Violations of Best Practice/legacy/AutoBoxing.ql @@ -72,12 +72,16 @@ predicate rebox(Assignment e, Variable v) { from Expr e, string conv where - boxed(e) and conv = "This expression is implicitly boxed." - or - unboxed(e) and conv = "This expression is implicitly unboxed." - or - exists(Variable v | rebox(e, v) | - conv = - "This expression implicitly unboxes, updates, and reboxes the value of '" + v.getName() + "'." + e.getFile().isJavaSourceFile() and + ( + boxed(e) and conv = "This expression is implicitly boxed." + or + unboxed(e) and conv = "This expression is implicitly unboxed." + or + exists(Variable v | rebox(e, v) | + conv = + "This expression implicitly unboxes, updates, and reboxes the value of '" + v.getName() + + "'." + ) ) select e, conv diff --git a/java/ql/test/kotlin/query-tests/AutoBoxing/AutoBoxing.expected b/java/ql/test/kotlin/query-tests/AutoBoxing/AutoBoxing.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/java/ql/test/kotlin/query-tests/AutoBoxing/AutoBoxing.qlref b/java/ql/test/kotlin/query-tests/AutoBoxing/AutoBoxing.qlref new file mode 100644 index 00000000000..f116f3bd8b4 --- /dev/null +++ b/java/ql/test/kotlin/query-tests/AutoBoxing/AutoBoxing.qlref @@ -0,0 +1 @@ +Violations of Best Practice/legacy/AutoBoxing.ql diff --git a/java/ql/test/kotlin/query-tests/AutoBoxing/Test.kt b/java/ql/test/kotlin/query-tests/AutoBoxing/Test.kt new file mode 100644 index 00000000000..ca3aa52b2c9 --- /dev/null +++ b/java/ql/test/kotlin/query-tests/AutoBoxing/Test.kt @@ -0,0 +1,5 @@ +fun foo(x: Int?) { + if (x != null) { + println(x) + } +}