diff --git a/java/ql/src/Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql b/java/ql/src/Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql index 814a45bef6d..9b87a358905 100644 --- a/java/ql/src/Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql +++ b/java/ql/src/Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql @@ -92,13 +92,16 @@ class ComparisonOrEquality extends BinaryExpr { from Expr e, string pattern, string rewrite where - e.(BoolCompare).simplify(pattern, rewrite) - or - conditionalWithBool(e, pattern, rewrite) - or - e.(LogNotExpr).getExpr().(ComparisonOrEquality).negate(pattern, rewrite) - or - e.(LogNotExpr).getExpr() instanceof LogNotExpr and - pattern = "!!A" and - rewrite = "A" + e.getFile().isJavaSourceFile() and + ( + e.(BoolCompare).simplify(pattern, rewrite) + or + conditionalWithBool(e, pattern, rewrite) + or + e.(LogNotExpr).getExpr().(ComparisonOrEquality).negate(pattern, rewrite) + or + e.(LogNotExpr).getExpr() instanceof LogNotExpr and + pattern = "!!A" and + rewrite = "A" + ) select e, "Expressions of the form \"" + pattern + "\" can be simplified to \"" + rewrite + "\"." diff --git a/java/ql/test/kotlin/query-tests/SimplifyBoolExpr/SimplifyBoolExpr.expected b/java/ql/test/kotlin/query-tests/SimplifyBoolExpr/SimplifyBoolExpr.expected index 456ed9af9b7..e69de29bb2d 100644 --- a/java/ql/test/kotlin/query-tests/SimplifyBoolExpr/SimplifyBoolExpr.expected +++ b/java/ql/test/kotlin/query-tests/SimplifyBoolExpr/SimplifyBoolExpr.expected @@ -1 +0,0 @@ -| SimplifyBoolExpr.kt:8:8:8:16 | ... (value equals) ... | Expressions of the form "A == true" can be simplified to "A". |