From 91774099fad685edd5a0fb022e5e1ef7904a82b8 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Thu, 9 Nov 2023 15:29:57 +0000 Subject: [PATCH] Write-only container query: account for implicitly-initialised variables --- java/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql b/java/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql index 8002c8d68411..8c8cb6105b3e 100644 --- a/java/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql +++ b/java/ql/src/Likely Bugs/Collections/WriteOnlyContainer.ql @@ -39,6 +39,6 @@ where ) and // Also, any value that `v` is initialized to is a new container, forall(Expr e | e = v.getAnAssignedValue() | e instanceof ClassInstanceExpr) and - // and `v` is not implicitly initialized by a for-each loop. - not exists(EnhancedForStmt efs | efs.getVariable().getVariable() = v) + // and `v` is not implicitly initialized + not v.(LocalVariableDecl).getDeclExpr().hasImplicitInit() select v, "The contents of this container are never accessed."