Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.assertj.core.util.VisibleForTesting
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
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,28 @@ class CodeWhispererUserModificationTracker(private val project: Project) : Dispo
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) {
LOG.warn {
"Invalid range for suggestion ${acceptedSuggestion.requestId}: " +
"start=$start, end=$end, docLength=${document.textLength}"
}
sendModificationTelemetry(acceptedSuggestion, null)
sendUserModificationTelemetryToServiceAPI(acceptedSuggestion)
return
}
}

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