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

IndexOutOfBoundsException #1631

Closed
falvarez opened this issue Apr 28, 2021 · 3 comments
Closed

IndexOutOfBoundsException #1631

falvarez opened this issue Apr 28, 2021 · 3 comments

Comments

@falvarez
Copy link

Software version:

PhpStorm 2021.1.1
Build #PS-211.7036.8, built on April 15, 2021
Runtime version: 11.0.10+9-b1341.35 x86_64
VM: Dynamic Code Evolution 64-Bit Server VM by JetBrains s.r.o.
macOS 10.14.6
GC: ParNew, ConcurrentMarkSweep
Memory: 1981M
Cores: 8
Registry: run.processes.with.pty=TRUE
Non-Bundled Plugins: indent-rainbow.indent-rainbow (1.6.1), net.seesharpsoft.intellij.plugins.csv (2.16.3), NEON support (0.5.1), de.espend.idea.laravel (0.15.4), de.espend.idea.php.annotation (8.0.0), fr.adrienbrault.idea.symfony2plugin (0.23.208)

StackTrace:

java.lang.StringIndexOutOfBoundsException: begin 0, end 73, length 60
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
	at java.base/java.lang.String.substring(String.java:1874)
	at fr.adrienbrault.idea.symfony2plugin.util.completion.PhpConstGotoCompletionProvider.getLookupElements(PhpConstGotoCompletionProvider.java:49)
	at fr.adrienbrault.idea.symfony2plugin.codeInsight.completion.CompletionContributor$1.addCompletions(CompletionContributor.java:51)
	at com.intellij.codeInsight.completion.CompletionProvider.addCompletionVariants(CompletionProvider.java:34)
	at com.intellij.codeInsight.completion.CompletionContributor.fillCompletionVariants(CompletionContributor.java:156)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:77)
	at com.intellij.codeInsight.completion.CompletionResultSet.runRemainingContributors(CompletionResultSet.java:154)
	at com.intellij.codeInsight.completion.CompletionResultSet.runRemainingContributors(CompletionResultSet.java:146)
	at com.intellij.codeInsight.completion.CompletionResultSet.runRemainingContributors(CompletionResultSet.java:142)
	at com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor$1.addCompletions(LiveTemplateCompletionContributor.java:89)
	at com.intellij.codeInsight.completion.CompletionProvider.addCompletionVariants(CompletionProvider.java:34)
	at com.intellij.codeInsight.completion.CompletionContributor.fillCompletionVariants(CompletionContributor.java:156)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:77)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:60)
	at com.intellij.codeInsight.completion.CompletionService.performCompletion(CompletionService.java:133)
	at com.intellij.codeInsight.completion.BaseCompletionService.performCompletion(BaseCompletionService.java:41)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.lambda$calculateItems$12(CompletionProgressIndicator.java:863)
	at com.intellij.util.indexing.FileBasedIndex.lambda$ignoreDumbMode$0(FileBasedIndex.java:163)
	at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111)
	at com.intellij.util.indexing.FileBasedIndexEx.ignoreDumbMode(FileBasedIndexEx.java:574)
	at com.intellij.util.indexing.FileBasedIndex.ignoreDumbMode(FileBasedIndex.java:162)
	at com.intellij.util.indexing.DumbModeAccessType.ignoreDumbMode(DumbModeAccessType.java:43)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.calculateItems(CompletionProgressIndicator.java:859)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.runContributors(CompletionProgressIndicator.java:847)
	at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$6(CodeCompletionHandlerBase.java:353)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$tryReadOrCancel$5(CompletionThreading.java:172)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1096)
	at com.intellij.codeInsight.completion.AsyncCompletion.tryReadOrCancel(CompletionThreading.java:170)
	at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$7(CodeCompletionHandlerBase.java:345)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$0(CompletionThreading.java:95)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:178)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:688)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:634)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:64)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:165)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$1(CompletionThreading.java:91)
	at com.intellij.util.RunnableCallable.call(RunnableCallable.java:20)
	at com.intellij.util.RunnableCallable.call(RunnableCallable.java:11)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.call(ApplicationImpl.java:265)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:834)
@adamwojs
Copy link
Contributor

adamwojs commented May 8, 2021

Issue could be reproduced using the following steps:

  1. Create the following DIC configuration
services:
    App\Service\Foo:
        arguments:
            - !php/const App\Service\Bar::FOO

App\Service\Foo and App\Service\Bar are existing classes.

  1. Place cursor in the middle of const reference e.g.
services:
    App\Service\Foo:
        arguments:
            - !php/const App\Service<cursor>\Bar::FOO
  1. Trigger code completion

@Haehnchen
Copy link
Owner

fixed via #1641

@adamwojs
Copy link
Contributor

fixed via #1641

Unfortunately problem is still reproducible. #1641 was little bit different case which I found while trying to reproduce this issue.

TL;DR

String classFQN = prefix.substring(0, getElement().getText().indexOf(SCOPE_OPERATOR));

should be changed to

String classFQN = prefix.substring(0, prefix.indexOf(SCOPE_OPERATOR));

in https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/completion/PhpConstGotoCompletionProvider.java#L49

Detailed explanation

It's what happens in PhpConstGotoCompletionProvider#getLookupElements for #1631 (comment) scenario:

getElement().getText() is App\ServIntellijIdeaRulezzz ice\Bar::FOO (length 40). We are removing com.intellij.codeInsight.completion.CompletionUtil#DUMMY_IDENTIFIER_TRIMMED from element text

final String prefix = getElement().getText().replace(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED, "");

so prefix become App\Serv ice\Bar::FOO (length is 21).

When we reach line 49

String classFQN = prefix.substring(0, getElement().getText().indexOf(SCOPE_OPERATOR));

we are looking for scope operator position to extract FQCN from string using getElement().getText(). The result is 35 what is above prefix length (21) and substring throws exception.

I can open PR 😉

adamwojs added a commit to adamwojs/idea-php-symfony2-plugin that referenced this issue May 16, 2021
adamwojs added a commit to adamwojs/idea-php-symfony2-plugin that referenced this issue May 16, 2021
…fBoundsException when cursor is before scope operator
Haehnchen added a commit that referenced this issue May 18, 2021
Fixed #1631: PhpConstGotoCompletionProvider throws IndexOutOfBoundsException when cursor is before scope operator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants