Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Amazon Q: Prevent IndexOutOfBoundsException by adding boundary checks for invalid range markers (#5187)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import software.amazon.awssdk.services.codewhispererruntime.model.CodeWhispererRuntimeException
import software.aws.toolkits.core.utils.debug
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.warn

Check warning on line 22 in plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererUserModificationTracker.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWhispererClientAdaptor
import software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererModelConfigurator
Expand Down Expand Up @@ -154,14 +155,24 @@
private fun emitTelemetryOnSuggestion(acceptedSuggestion: AcceptedSuggestionEntry) {
val file = acceptedSuggestion.vFile

if (file == null || (!file.isValid)) {
if (file == null || (!file.isValid) || !acceptedSuggestion.range.isValid) {
sendModificationTelemetry(acceptedSuggestion, null)
sendUserModificationTelemetryToServiceAPI(acceptedSuggestion)
} else {
// Will remove this later when we truly don't need toolkit user modification telemetry anymore
val document = runReadAction {
FileDocumentManager.getInstance().getDocument(file)
}
val start = acceptedSuggestion.range.startOffset
val end = acceptedSuggestion.range.endOffset
if (document != null) {
if (start < 0 || end < start || end > document.textLength) {
sendModificationTelemetry(acceptedSuggestion, null)
sendUserModificationTelemetryToServiceAPI(acceptedSuggestion)
return
}
}

val currentString = document?.getText(
TextRange(acceptedSuggestion.range.startOffset, acceptedSuggestion.range.endOffset)
)
Expand Down
Loading