From 5b03c88414197089042d87299d0ac2782bf8ec3e Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Tue, 7 Jan 2025 14:01:21 -0800 Subject: [PATCH] ModelAwareGradleLintRule: handle receiver exceptions --- .../lint/rule/ModelAwareGradleLintRule.groovy | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/groovy/com/netflix/nebula/lint/rule/ModelAwareGradleLintRule.groovy b/src/main/groovy/com/netflix/nebula/lint/rule/ModelAwareGradleLintRule.groovy index a98d8015..e8d2032d 100644 --- a/src/main/groovy/com/netflix/nebula/lint/rule/ModelAwareGradleLintRule.groovy +++ b/src/main/groovy/com/netflix/nebula/lint/rule/ModelAwareGradleLintRule.groovy @@ -36,25 +36,29 @@ abstract class ModelAwareGradleLintRule extends GradleLintRule { Map> projectDefaultImports = null TypeInformation receiver(MethodCallExpression call) { - List fullCallStack = typedDslStack(callStack + call) - List typedStack = [] - for (Expression currentMethod in fullCallStack) { - if (typedStack.empty) { - typedStack.add(new TypeInformation(project)) - } - while (!typedStack.empty) { - def current = typedStack.last() - def candidate = findDirectCandidate(current, currentMethod) - if (candidate != null) { - typedStack.add(candidate) - break + try { + List fullCallStack = typedDslStack(callStack + call) + List typedStack = [] + for (Expression currentMethod in fullCallStack) { + if (typedStack.empty) { + typedStack.add(new TypeInformation(project)) + } + while (!typedStack.empty) { + def current = typedStack.last() + def candidate = findDirectCandidate(current, currentMethod) + if (candidate != null) { + typedStack.add(candidate) + break + } + typedStack.removeLast() } - typedStack.removeLast() } - } - if (typedStack.size() >= 2) { //there should be the method return type and the receiver at least - return typedStack[-2] - } else { + if (typedStack.size() >= 2) { //there should be the method return type and the receiver at least + return typedStack[-2] + } else { + return null + } + } catch (Exception e) { return null } }