aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
752 stars 216 forks source link

StringIndexOutOfBoundsException (no CodeWhisperer) #3934

Open socketbox opened 11 months ago

socketbox commented 11 months ago

Describe the bug Without CodeWhisperer enabled, but with the AWS Toolkit installed, I receive the following exception:

java.lang.StringIndexOutOfBoundsException: begin 0, end 75, length 31
    at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
    at java.base/java.lang.String.substring(String.java:2709)
    at com.intellij.openapi.util.TextRange.substring(TextRange.java:105)
    at com.intellij.openapi.editor.Document.getText(Document.java:48)
    at software.aws.toolkits.jetbrains.services.codewhisperer.editor.CodeWhispererEditorUtil.extractCaretContext(CodeWhispererEditorUtil.kt:40)
    at software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutoTriggerService$shouldTriggerClassifier$caretContext$1.invoke(CodeWhispererAutoTriggerService.kt:141)
    at software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutoTriggerService$shouldTriggerClassifier$caretContext$1.invoke(CodeWhispererAutoTriggerService.kt:141)
    at com.intellij.openapi.application.ActionsKt.runReadAction$lambda$3(actions.kt:31)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:909)
    at com.intellij.openapi.application.ActionsKt.runReadAction(actions.kt:31)
    at software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutoTriggerService.shouldTriggerClassifier(CodeWhispererAutoTriggerService.kt:141)
    at software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutoTriggerService$tryInvokeAutoTrigger$classifierResult$2.invoke(CodeWhispererAutoTriggerService.kt:54)
    at software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutoTriggerService$tryInvokeAutoTrigger$classifierResult$2.invoke(CodeWhispererAutoTriggerService.kt:54)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutoTriggerService.tryInvokeAutoTrigger$lambda$0(CodeWhispererAutoTriggerService.kt:54)
    at software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutoTriggerService.tryInvokeAutoTrigger(CodeWhispererAutoTriggerService.kt:60)
    at software.aws.toolkits.jetbrains.services.codewhisperer.editor.CodeWhispererEnterHandler.executeWriteAction$lambda$0(CodeWhispererEnterHandler.kt:25)
    at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:272)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)

To reproduce Can't really say when this first appeared, as the blinking red "IDE Internal Errors" button is at the edge of my vision, so I don't know what might have triggered it, though I was in a Markdown document at the time (when I noticed it).

Expected behavior No exceptions from this plugin.

Your Environment

Linux 6.2.0-34-generic
PyCharm 2023.2.3 (Professional Edition)
Build #PY-232.10072.31, built on October 12, 2023
Runtime version: 17.0.8.1+7-b1000.32 amd64
aws.toolkit (1.84-232)
aws-cli/2.11.16 Python/3.11.3 Linux/6.2.0-34-generic exe/x86_64.linuxmint.21 prompt/off 
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
leigaol commented 9 months ago

Hi @socketbox , could you upgrade your AWS Toolkit for JetBrains to v2.1+ and see if this happens again? Thank you!