Sonar-php IndexOutOfBoundsException

php

(andreas parschalk) #1

Template for a good bug report, formatted with Markdown:

  • versions used (SonarQube, Scanner, Plugin, and any relevant extension)
15:12:40.380 INFO: SonarQube Scanner 3.2.0.1227
15:12:40.380 INFO: Java 1.8.0_181 Oracle Corporation (64-bit)
15:12:40.380 INFO: Linux 2.6.32-754.6.3.el6.x86_64 amd64

15:12:42.195 DEBUG: Plugins:
15:12:42.195 DEBUG:   * SonarPython 1.10.0.2131 (python)
15:12:42.195 DEBUG:   * SonarCSS 1.0.1.508 (cssfamily)
15:12:42.195 DEBUG:   * SonarGo 1.1.0.1612 (go)
15:12:42.195 DEBUG:   * SonarKotlin 1.0.1.965 (kotlin)
15:12:42.196 DEBUG:   * Svn 1.8.0.1168 (scmsvn)
15:12:42.196 DEBUG:   * SonarJS 5.0.0.6962 (javascript)
15:12:42.196 DEBUG:   * SonarC# 7.3.2.6129 (csharp)
15:12:42.196 DEBUG:   * SonarJava 5.6.1.15064 (java)
15:12:42.196 DEBUG:   * LDAP 2.2.0.608 (ldap)
15:12:42.196 DEBUG:   * Git 1.4.1.1128 (scmgit)
15:12:42.196 DEBUG:   * SonarFlex 2.4.0.1222 (flex)
15:12:42.196 DEBUG:   * SonarXML 1.5.1.1452 (xml)
15:12:42.196 DEBUG:   * SonarPHP 2.14.0.3569 (php)
15:12:42.196 DEBUG:   * SonarTS 1.7.0.2893 (typescript)
  • error observed (wrap logs/code around triple quote ``` for proper formatting)
15:12:59.035 ERROR: Error during SonarQube Scanner execution
org.sonar.plugins.php.AnalysisException: Could not analyse Abstract.php
	at org.sonar.plugins.php.PHPSensor.analyseFile(PHPSensor.java:197)
	at org.sonar.plugins.php.PHPSensor.analyseFiles(PHPSensor.java:149)
	at org.sonar.plugins.php.PHPSensor.execute(PHPSensor.java:122)
	at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:45)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:88)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:62)
	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:166)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:300)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:295)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:269)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)
	at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0
	at java.util.Collections$EmptyList.get(Collections.java:4454)
	at org.sonar.php.checks.DuplicateBranchImplementationCheck.raiseIssue(DuplicateBranchImplementationCheck.java:62)
	at org.sonar.php.checks.DuplicateBranchImplementationCheck.lambda$onAllEquivalentBranches$0(DuplicateBranchImplementationCheck.java:39)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.stream.SliceOps$1$1.accept(SliceOps.java:204)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at org.sonar.php.checks.DuplicateBranchImplementationCheck.onAllEquivalentBranches(DuplicateBranchImplementationCheck.java:39)
	at org.sonar.php.checks.utils.AbstractDuplicateBranchImplementationCheck.visitSwitchStatement(AbstractDuplicateBranchImplementationCheck.java:104)
	at org.sonar.php.tree.impl.statement.SwitchStatementTreeImpl.accept(SwitchStatementTreeImpl.java:157)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.scan(PHPVisitorCheck.java:547)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.visitBlock(PHPVisitorCheck.java:277)
	at org.sonar.php.tree.impl.statement.BlockTreeImpl.accept(BlockTreeImpl.java:78)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.scan(PHPVisitorCheck.java:547)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.visitMethodDeclaration(PHPVisitorCheck.java:152)
	at org.sonar.php.tree.impl.declaration.MethodDeclarationTreeImpl.accept(MethodDeclarationTreeImpl.java:118)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.scan(PHPVisitorCheck.java:547)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.visitClassDeclaration(PHPVisitorCheck.java:192)
	at org.sonar.php.tree.impl.declaration.ClassDeclarationTreeImpl.accept(ClassDeclarationTreeImpl.java:168)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.scan(PHPVisitorCheck.java:547)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.visitScript(PHPVisitorCheck.java:482)
	at org.sonar.php.checks.utils.AbstractDuplicateBranchCheck.visitScript(AbstractDuplicateBranchCheck.java:41)
	at org.sonar.php.tree.impl.ScriptTreeImpl.accept(ScriptTreeImpl.java:70)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.scan(PHPVisitorCheck.java:547)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.visitCompilationUnit(PHPVisitorCheck.java:487)
	at org.sonar.plugins.php.api.visitors.PHPVisitorCheck.analyze(PHPVisitorCheck.java:570)
	at org.sonar.php.PHPAnalyzer.analyze(PHPAnalyzer.java:74)
	at org.sonar.plugins.php.PHPSensor.analyseFile(PHPSensor.java:187)
	... 33 more
  • steps to reproduce

analyze switch statement with empty case and a second case containing only a break:

switch($a) {
  case 1:
  case 2: break;
}
  • potential workaround

(Elena Vilchik) #3

Hey,

Thanks for reporting, ticket is creared https://jira.sonarsource.com/browse/SONARPHP-852

And many thanks for such well-detailed post, it sped up a lot my investigations!