ERROR: SonarQube is unable to analyze file

java

(vicky) #1

SQ -6.7.4
Scanner-3.2
Hi Team,

While running the analysis i am getting the following error:

13:20:54.435 ERROR: Error during SonarQube Scanner execution
org.sonar.squidbridge.api.AnalysisException: SonarQube is unable to analyze file : 'C:\Program Files (x86)\Jenkins\workspace\modules\dfm-autosupport\src\main\java\com\netapp\dfm\autosupport\AutoSupportMain.java'
        at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:105)
        at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:68)
        at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:119)
        at org.sonar.java.JavaSquid.scan(JavaSquid.java:113)
        at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:84)
        at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
        at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
        at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
        at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
        at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:177)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:291)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:286)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:264)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
        at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
        at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
        at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
        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) must be less than size (0)
        at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
        at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
        at com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
        at org.sonar.java.ast.parser.ListTreeImpl.get(ListTreeImpl.java:186)
        at org.sonar.java.ast.parser.ListTreeImpl.get(ListTreeImpl.java:38)
        at org.sonar.samples.java.checks.SentenceCheck.visitMethodInvocation(SentenceCheck.java:122)
        at org.sonar.java.model.expression.MethodInvocationTreeImpl.accept(MethodInvocationTreeImpl.java:96)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitExpressionStatement(BaseTreeVisitor.java:102)
        at org.sonar.java.model.statement.ExpressionStatementTreeImpl.accept(ExpressionStatementTreeImpl.java:65)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitBlock(BaseTreeVisitor.java:86)
        at org.sonar.java.model.statement.BlockTreeImpl.accept(BlockTreeImpl.java:77)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitMethod(BaseTreeVisitor.java:81)
        at org.sonar.java.model.declaration.MethodTreeImpl.accept(MethodTreeImpl.java:218)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitClass(BaseTreeVisitor.java:70)
        at org.sonar.java.model.declaration.ClassTreeImpl.accept(ClassTreeImpl.java:202)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitCompilationUnit(BaseTreeVisitor.java:55)
        at org.sonar.java.model.JavaTree$CompilationUnitTreeImpl.accept(JavaTree.java:189)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
        at org.sonar.samples.java.checks.SentenceCheck.scanFile(SentenceCheck.java:31)
        at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:117)
        at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:96)
        ... 36 more

(G Ann Campbell) #3

Hi,

What version of SonarJava are you using? You can find the answer in Administration > Marketplace, or alternately using the Web API (api/plugins/installed). If you go the latter route, please don’t dump the entire JSON contents here, but use something like https://jsonformatter.curiousconcept.com to format the result and then grab the value you need.

 
Ann


(Michael Gumowski) #4

Hello @vicky,

Looking at the stacktrace from you analysis, I’m pretty sure it comes from a buggy custom rules, and not a rule from SonarJava analyzer.

You should check if your SonarQube instance has a java custom rule plugin installed, which would contain a rule implemented in org.sonar.samples.java.checks.SentenceCheck. From what I can see there, that’s the one causing the analysis to fail… Which would say that the issue is on your side.

Looking at the log, I’m confident this “SentenceCheck” rule is trying to access some of the nodes related to a method invocation, without testing for the size of the list (arguments maybe?).

Note that it would help if you could specify the plugins you installed, as requested by @ganncamp. In particular, knowing if there is custom plugins, and what is the version of SonarJava.

Regards,
Michael


(vicky) #5

Hi Michael,

The problem was some methods had 0 arguments, so calling tree.arguments().get(0) to get the first argument resulted in the Exception. I added a try/catch statement to handle that case and the error is gone now.

Thanks for your response!


(Michael Gumowski) #6

Mmmh, don’t you think it would be cleaner to maybe test the number of arguments before accessing it!?
Exception-based coding is really not a good practice, and I would not recommend it.

Why not doing something such as:

Arguments args = tree.arguments();
if (!args.isEmpty()) {
  ExpressionTree firstArg = args.get(0);
  // do something then
}

(vicky) #7

Hi @Michael,

Yup that sounds good. Thanks for your help.