cedricziel / idea-php-typo3-plugin

TYPO3 CMS Plugins for IntelliJ IDEA / PhpStorm
MIT License
96 stars 8 forks source link

StringIndexOutOfBoundsException #335

Closed liayn closed 3 years ago

liayn commented 3 years ago
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
    at java.base/java.lang.String.substring(String.java:1841)
    at com.cedricziel.idea.typo3.provider.AbstractServiceLocatorTypeProvider.getBySignature(AbstractServiceLocatorTypeProvider.java:33)
    at com.jetbrains.php.PhpIndexImpl.getBySignatureInternal(PhpIndexImpl.java:636)
    at com.jetbrains.php.PhpIndexImpl.getBySignature(PhpIndexImpl.java:501)
    at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:137)
    at com.jetbrains.php.PhpIndexImpl.completeType(PhpIndexImpl.java:101)
    at com.jetbrains.php.lang.psi.resolve.types.PhpType.global(PhpType.java:560)
    at com.jetbrains.php.lang.inspections.PhpVoidFunctionResultUsedInspection.analyzeCall(PhpVoidFunctionResultUsedInspection.java:50)
    at com.jetbrains.php.lang.inspections.PhpVoidFunctionResultUsedInspection.access$000(PhpVoidFunctionResultUsedInspection.java:23)
    at com.jetbrains.php.lang.inspections.PhpVoidFunctionResultUsedInspection$1.visitPhpMethodReference(PhpVoidFunctionResultUsedInspection.java:41)
    at com.jetbrains.php.lang.psi.elements.impl.MethodReferenceImpl.accept(MethodReferenceImpl.java:28)
    at com.jetbrains.php.lang.psi.elements.impl.PhpASTElementImpl.accept(PhpASTElementImpl.java:26)
    at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:65)
    at com.intellij.codeInspection.InspectionEngine.createVisitorAndAcceptElements(InspectionEngine.java:56)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.runToolOnElements(LocalInspectionsPass.java:294)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$3(LocalInspectionsPass.java:263)
    at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:155)
    at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:147)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$4(LocalInspectionsPass.java:262)
    at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:126)
    at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:115)
    at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$5(LocalInspectionsPass.java:262)
    at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:149)
    at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:162)
    at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:162)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1110)
    at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:105)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:629)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:581)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:117)
    at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:96)
    at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:170)
    at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:182)
    at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96)
    at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
liayn commented 3 years ago

Log output:

2020-10-08 15:14:03,706 [16941221]   WARN - ractServiceLocatorTypeProvider - Unable to find PhpNamedElement by signature from "#M#C\TYPO3\CMS\Core\Context\UserAspect.get%id" 
...
2020-10-14 00:56:59,577 [144041314]   WARN - ractServiceLocatorTypeProvider - Unable to find PhpNamedElement by signature from "#M#M#?#M#C\TYPO3\CMS\Core\Utility\GeneralUtility.makeInstance%#K#C\TYPO3\CMS\Core\Context\Context.class.getAspect.get|#M#?frontend.user.get|#M#M#?#M#C\TYPO3\CMS\Core\Utility\GeneralUtility.makeInstance?\TYPO3\CMS\Core\Context\Context.getAspect.get|#M#M#M#C\TYPO3\CMS\Core\Utility\GeneralUtility.makeInstance.getAspect.get%id" 
mat-hew1 commented 3 years ago

Here a code to reproduce:

<?php
declare(strict_types = 1);

namespace Test\TestProject;

use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class TestController extends ActionController
{
    /**
     * @var Context
     */
    protected $context;

    /**
     * @param Context $context
     */
    public function injectContext(Context $context)
    {
        $this->context = $context;
    }

    /**
     * @throws AspectNotFoundException
     * @throws AspectPropertyNotFoundException
     */
    protected function getCurrentUserUid(): string
    {
        return $this->context->getAspect('frontend.user')->get('id');
    }
}