From 0d276ff1ecf92eff341234f31211d1b99c771281 Mon Sep 17 00:00:00 2001 From: Niklas Baudy Date: Wed, 10 Aug 2022 12:33:02 +0200 Subject: [PATCH] IDEA: UnusedQueryInspection - fix ArrayIndexOutOfBoundsException. (#3427) * IDEA: UnusedQueryInspection - fix ArrayIndexOutOfBoundsException. * Update sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt Co-authored-by: Alexander Perfilyev Co-authored-by: Alexander Perfilyev --- .../intellij/inspections/UnusedQueryInspection.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt index 5367a942881..773a9c01646 100644 --- a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt +++ b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt @@ -38,7 +38,12 @@ internal class UnusedQueryInspection : LocalInspectionTool() { fileName, GlobalSearchScope.moduleScope(module), ).firstOrNull() as KtFile? ?: return PsiElementVisitor.EMPTY_VISITOR - val allMethods = generatedFile.classes[0].methods + val allMethods = generatedFile.classes.firstOrNull()?.methods + + if (allMethods == null) { + return PsiElementVisitor.EMPTY_VISITOR + } + return object : SqlDelightVisitor() { override fun visitStmtIdentifier(o: SqlDelightStmtIdentifier) = ignoreInvalidElements { if (o !is StmtIdentifierMixin || o.identifier() == null) {