@@ -111,8 +111,8 @@ private void checkCallExpression(SubscriptionContext context) {
111111 }
112112
113113 private static void addIssue (SubscriptionContext context , CallExpression callExpression ) {
114- Optional <Tree > secondary = sensitiveArgumentValue (callExpression );
115- secondary .ifPresent (tree -> context .addIssue (callExpression , MESSAGE ).secondary (tree , null ));
114+ Optional <Tree > secondary = sensitiveArgumentValue (callExpression , context );
115+ secondary .ifPresent (tree -> context .addIssue (callExpression , MESSAGE ).secondary (tree , null ));
116116 }
117117
118118 private static boolean isException (CallExpression callExpression , String functionName ) {
@@ -123,7 +123,7 @@ private static boolean isException(CallExpression callExpression, String functio
123123 return argListNode .isEmpty ();
124124 }
125125
126- private static Optional <Tree > sensitiveArgumentValue (CallExpression callExpression ) {
126+ private static Optional <Tree > sensitiveArgumentValue (CallExpression callExpression , SubscriptionContext ctx ) {
127127 List <Argument > argListNode = callExpression .arguments ();
128128 if (argListNode .isEmpty ()) {
129129 return Optional .empty ();
@@ -134,14 +134,27 @@ private static Optional<Tree> sensitiveArgumentValue(CallExpression callExpressi
134134 }
135135 Expression expression = getExpression (((RegularArgument ) arg ).expression ());
136136 if (expression .is (Tree .Kind .NAME )) {
137- expression = Expressions . singleAssignedValue ((Name ) expression );
137+ return findFormattedValue ((Name ) expression , ctx );
138138 }
139- if (expression != null && isFormatted (expression )) {
139+ if (isFormatted (expression )) {
140140 return Optional .of (expression );
141141 }
142142 return Optional .empty ();
143143 }
144144
145+ private static Optional <Tree > findFormattedValue (Name name , SubscriptionContext ctx ) {
146+ Set <Expression > values = ctx .valuesAtLocation (name );
147+ if (!values .isEmpty ()) {
148+ return values .stream ()
149+ .filter (SQLQueriesCheck ::isFormatted )
150+ .findFirst ()
151+ .map (Tree .class ::cast );
152+ }
153+ return Optional .ofNullable (Expressions .singleAssignedValue (name ))
154+ .filter (SQLQueriesCheck ::isFormatted )
155+ .map (Tree .class ::cast );
156+ }
157+
145158 private static boolean isFormatted (Expression tree ) {
146159 FormattedStringVisitor visitor = new FormattedStringVisitor ();
147160 tree .accept (visitor );
0 commit comments