IndexOutOfBoundsException in SonarLint for IntelliJ


  • Java: JetBrains s.r.o. 17.0.9
  • OS: Mac OS X aarch64
  • IDE: IntelliJ IDEA 2023.2.5
  • SonarLint:

*** exception class was changed or removed

  Exceptions occurred on invoking the intention 'SonarLint: Inline expression' on a copy of the file.
  java.lang.IndexOutOfBoundsException: Wrong endOffset: 30770; documentLength: 30764
at c.ij.oa.editor.impl.DocumentImpl.assertBounds(
at c.ij.oa.editor.impl.DocumentImpl.replaceString(
at c.ij.oa.editor.impl.DocumentImpl.replaceString(
at c.ij.codeInsight.intention.IntentionAction.generatePreview(
at c.ij.codeInsight.intention.impl.IntentionActionWithTextCaching$MyIntentionAction.generatePreview(
at c.ij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview$lambda$3$lambda$2$lambda$1(IntentionPreviewComputable.kt:124)
at c.ij.model.SideEffectGuard.computeWithAllowedSideEffects(
at c.ij.model.SideEffectGuard.computeWithoutSideEffects(
at c.ij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview$lambda$3$lambda$2(IntentionPreviewComputable.kt:123)
at c.ij.psi.impl.source.PostprocessReformattingAspectImpl.lambda$postponeFormattingInside$2(
at c.ij.psi.impl.source.PostprocessReformattingAspectImpl.postponeFormattingInside(

Hi @Cyril_Dragomyr, thank you for your report!

It happened when you tried to preview the quick fix, I believe there is a short time window where this issue can happen because the document is being changed. We recently improved the behavior of this, but it seems it’s still not enough. We will try to improve it even further, and as a result, I created this bug ticket.

If you have more details to share, do not hesitate. Did you do anything in particular? Can you reproduce the issue?

Unfortunately, this kind of issue happens randomly and it’s very hard to list steps to reproduce