Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IndexOutOfBoundsException after deleting text when editing application.properties #1116

Closed
gastaldi opened this issue Aug 21, 2023 · 11 comments · Fixed by #1123
Closed
Assignees
Labels
bug Something isn't working completion lsp4ij LSP client for IJ validation
Milestone

Comments

@gastaldi
Copy link
Contributor

While editing an application.properties (like the one in https://github.com/quarkiverse/quarkus-ironjacamar/blob/main/integration-tests/src/main/resources/application.properties), I get the following IDE internal error:

   ExternalToolPass: 
   
   com.intellij.diagnostic.PluginException: annotator: com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.LSPDiagnosticAnnotator@32021090 (class com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.LSPDiagnosticAnnotator) [Plugin: com.redhat.devtools.intellij.quarkus]
	at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:23)
	at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:89)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.processError(ExternalToolPass.java:251)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doApply(ExternalToolPass.java:227)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doApply(ExternalToolPass.java:216)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.lambda$run$1(ExternalToolPass.java:168)
	at com.intellij.openapi.application.ReadAction.lambda$run$1(ReadAction.java:64)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:923)
	at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:76)
	at com.intellij.openapi.application.ReadAction.run(ReadAction.java:63)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.lambda$run$2(ExternalToolPass.java:165)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:360)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.run(ExternalToolPass.java:162)
	at com.intellij.util.ui.update.Update.runUpdate(Update.java:114)
	at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:348)
	at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:338)
	at com.intellij.util.ui.update.MergingUpdateQueue.doFlush(MergingUpdateQueue.java:295)
	at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:277)
	at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:246)
	at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:254)
	at com.intellij.util.Alarm$Request.runSafely(Alarm.java:373)
	at com.intellij.util.Alarm$Request.run(Alarm.java:360)
	at com.intellij.util.concurrency.Propagation.contextAwareCallable$lambda$2(propagation.kt:328)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:272)
	at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:249)
	at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:31)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:227)
	at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:218)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:215)
	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)
Caused by: java.lang.IndexOutOfBoundsException: Wrong line: 12. Available lines count: 3
	at com.intellij.openapi.editor.impl.LineSet.checkLineIndex(LineSet.java:197)
	at com.intellij.openapi.editor.impl.LineSet.getLineStart(LineSet.java:178)
	at com.intellij.openapi.editor.impl.DocumentImpl.getLineStartOffset(DocumentImpl.java:1012)
	at com.redhat.devtools.intellij.lsp4ij.LSPIJUtils.toOffset(LSPIJUtils.java:167)
	at com.redhat.devtools.intellij.lsp4ij.LSPIJUtils.toTextRange(LSPIJUtils.java:205)
	at com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.LSPDiagnosticAnnotator.createAnnotation(LSPDiagnosticAnnotator.java:76)
	at com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.LSPDiagnosticAnnotator.apply(LSPDiagnosticAnnotator.java:70)
	at com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.LSPDiagnosticAnnotator.apply(LSPDiagnosticAnnotator.java:41)
	at com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl.applyExternalAnnotatorWithContext(AnnotationHolderImpl.java:253)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doApply(ExternalToolPass.java:224)
	... 40 more
@fbricon
Copy link
Contributor

fbricon commented Aug 21, 2023

Do you have steps to reproduce this issue? did you delete/overwrite large chunks of the file? line: 12. Available lines count: 3 suggests a big discrepancy between the actual document and what was used to compute diags

@gastaldi
Copy link
Contributor Author

@fbricon I don't know the exact steps, but I could reproduce it again by deleting several lines in that file

@angelozerr
Copy link
Contributor

@gastaldi have you this issue with 1.25?

@gastaldi
Copy link
Contributor Author

@angelozerr yes, 1.25.0.522

@fbricon
Copy link
Contributor

fbricon commented Aug 22, 2023

@gastaldi hard as I try, I can't reproduce. Which version of IJ are you using?

@gastaldi
Copy link
Contributor Author

IntelliJ IDEA 2023.2 (Ultimate Edition) - Build #IU-232.8660.185, built on July 26, 2023

@fbricon fbricon changed the title java.lang.IndexOutOfBoundsException: Wrong line: 12. Available lines count: 3 java.lang.IndexOutOfBoundsException when editing application.properties with Copilot turned on Aug 22, 2023
@fbricon
Copy link
Contributor

fbricon commented Aug 22, 2023

After a troubleshooting session with @gastaldi we figured out the problem occurred when GitHub Copilot is turned on and provides suggestions.

The workaround is to disable GitHub Copilot for properties files

@angelozerr
Copy link
Contributor

I dont understand the explanation. The original issue is about diagnostics not about completion suggestion, no?

The issue is that à diagnostic is reported but with wrong line. We should take care of that when textrange is built.

The question after that is why there is a wrong diagnostic?

I hope really that it is bot à problem with document synch. @gastaldi when yiu have this issue if you type à property have you completion, diagnostics?

@gastaldi
Copy link
Contributor Author

gastaldi commented Aug 23, 2023

@angelozerr @fbricon actually I now managed to reproduce it having the GitHub Copilot disabled, so I can confirm this isn't a problem with the plugin and GitHub Copilot.

To reproduce you need to delete lines from application.properties while having the auto-completion pop-up open

Here are a couple of videos showing how to reproduce the error. You need to restart the IDE when the error happens to reproduce it again:

With GitHub Pilot enabled

Screen.Recording.2023-08-22.at.23.52.16.mov

Without GH Pilot

Screen.Recording.2023-08-22.at.23.59.28.mov

@angelozerr
Copy link
Contributor

Thanks @gastaldi for your demo. I cannot reproduce it, but we need to take care of wrong diagnostic text editor that we should ignore.

@fbricon fbricon changed the title java.lang.IndexOutOfBoundsException when editing application.properties with Copilot turned on java.lang.IndexOutOfBoundsException after deleting text when editing application.properties Aug 23, 2023
@fbricon fbricon added bug Something isn't working completion labels Aug 23, 2023
@fbricon fbricon added this to the 1.26.0 milestone Aug 23, 2023
@angelozerr angelozerr added lsp4ij LSP client for IJ validation labels Aug 23, 2023
angelozerr added a commit to angelozerr/intellij-quarkus that referenced this issue Aug 23, 2023
editing application.properties

Fixes redhat-developer#1116

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr
Copy link
Contributor

@gastaldi I cannot reproduce your issue but I have created a PR #1123 which catch this error. This catch is important because LSP client cannot trust the language server and should take care of invalid text range for diagnostic.

if you have time please test the PR.

Here are a couple of videos showing how to reproduce the error. You need to restart the IDE when the error happens to reproduce it again:

I think the error is evry time but IJ caches the log error to avoid showing it on each key stroke.

angelozerr added a commit to angelozerr/intellij-quarkus that referenced this issue Aug 23, 2023
editing application.properties

Fixes redhat-developer#1116

Signed-off-by: azerr <azerr@redhat.com>
fbricon pushed a commit that referenced this issue Aug 24, 2023
editing application.properties

Fixes #1116

Signed-off-by: azerr <azerr@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completion lsp4ij LSP client for IJ validation
Projects
None yet
3 participants