From cd64faf635b207d84f5d680bf6f1aa85ead0a4f3 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Fri, 7 Oct 2022 09:13:10 +0200 Subject: [PATCH] Kotlin: ignore properties in `java/internal-representation-exposure` check --- .../Implementation Hiding/ExposeRepresentation.ql | 8 ++++++-- .../ExposeRepresentation/ExposeRepresentation.expected | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/java/ql/src/Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql b/java/ql/src/Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql index 8fe3d4e6ba6..9f24744fa0c 100644 --- a/java/ql/src/Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql +++ b/java/ql/src/Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql @@ -120,8 +120,12 @@ predicate exposesByStore(Callable c, Field f, Expr why, string whyText) { from Callable c, Field f, Expr why, string whyText where - exposesByReturn(c, f, why, whyText) or - exposesByStore(c, f, why, whyText) + ( + exposesByReturn(c, f, why, whyText) or + exposesByStore(c, f, why, whyText) + ) and + // Kotlin properties expose internal representation, but it's not accidental, so ignore them + not exists(Property p | p.getBackingField() = f) select c, c.getName() + " exposes the internal representation stored in field " + f.getName() + ". The value may be modified $@.", why.getLocation(), whyText diff --git a/java/ql/test/kotlin/query-tests/ExposeRepresentation/ExposeRepresentation.expected b/java/ql/test/kotlin/query-tests/ExposeRepresentation/ExposeRepresentation.expected index 64b3f15ca4e..e69de29bb2d 100644 --- a/java/ql/test/kotlin/query-tests/ExposeRepresentation/ExposeRepresentation.expected +++ b/java/ql/test/kotlin/query-tests/ExposeRepresentation/ExposeRepresentation.expected @@ -1 +0,0 @@ -| ExposesRep.kt:2:5:2:49 | getStrings | getStrings exposes the internal representation stored in field strings. The value may be modified $@. | User.kt:3:12:3:18 | User.kt:3:12:3:18 | after this call to getStrings |