From 7c9665a9510a2bdb5ba42baf95ec49d4cd9d3be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=84=E5=9D=9B?= Date: Mon, 5 Aug 2024 17:57:47 +0800 Subject: [PATCH] Fix ArrayIndexOutOfBoundsException in AliMissingOverrideAnnotationInspection Related to #999 Add checks for empty arrays in `AliMissingOverrideAnnotationInspection.kt` to prevent `ArrayIndexOutOfBoundsException`. * Add a check for empty `infos` array before accessing elements in the `buildFix` method. * Add a check for null `psiElement` before calling `buildFix` in the `manualBuildFix` method. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/alibaba/p3c/issues/999?shareId=XXXX-XXXX-XXXX-XXXX). --- .../AliMissingOverrideAnnotationInspection.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/standalone/AliMissingOverrideAnnotationInspection.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/standalone/AliMissingOverrideAnnotationInspection.kt index 9b4d0070d..070771a90 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/standalone/AliMissingOverrideAnnotationInspection.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/standalone/AliMissingOverrideAnnotationInspection.kt @@ -65,12 +65,20 @@ class AliMissingOverrideAnnotationInspection : MissingOverrideAnnotationInspecti override fun createOptionsPanel(): JComponent? = null override fun buildFix(vararg infos: Any): InspectionGadgetsFix? { + if (infos.isEmpty()) { + return null + } val fix = super.buildFix(*infos) ?: return null return DecorateInspectionGadgetsFix(fix, P3cBundle.getMessage("com.alibaba.p3c.idea.quickfix.standalone.AliMissingOverrideAnnotationInspection")) } - override fun manualBuildFix(psiElement: PsiElement, isOnTheFly: Boolean): LocalQuickFix? = buildFix(psiElement) + override fun manualBuildFix(psiElement: PsiElement, isOnTheFly: Boolean): LocalQuickFix? { + if (psiElement == null) { + return null + } + return buildFix(psiElement) + } override fun getDefaultLevel(): HighlightDisplayLevel = HighlightDisplayLevels.BLOCKER