SonarQube无法分析文件:foo: index(0)必须小于size(0)



我正在运行SonarQube 4.5.4服务器,并通过maven 3.0.5使用Sonar插件进行分析。我分析其他项目没有问题,但是在做Java AST扫描时给了我这个错误(请注意我删除了实际的Java源文件名):

01:15:45.429 [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project netbase: SonarQube is unable to analyze file : foo.java: index (0) must be less than size (0) -> [Help 1]
01:15:45.430 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project netbase: SonarQube is unable to analyze file : '/acc1/jenkins/workspace/backend-all-in-one-nightly/prospero-framework/src/main/java/com/accelovation/prospero/cluster/NodeImpl.java'
01:15:45.430    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
01:15:45.430    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
01:15:45.430    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
01:15:45.430    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
01:15:45.430    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
01:15:45.430    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
01:15:45.430    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
01:15:45.431    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
01:15:45.431    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
01:15:45.431    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
01:15:45.431    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
01:15:45.431    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
01:15:45.431    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
01:15:45.431    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
01:15:45.431    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
01:15:45.432    at java.lang.reflect.Method.invoke(Method.java:606)
01:15:45.432    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
01:15:45.432    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
01:15:45.432    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
01:15:45.432    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
01:15:45.432 Caused by: org.apache.maven.plugin.MojoExecutionException: SonarQube is unable to analyze file : '/acc1/jenkins/workspace/backend-all-in-one-nightly/prospero-framework/src/main/java/com/accelovation/prospero/cluster/NodeImpl.java'
01:15:45.432    at org.codehaus.mojo.sonar.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:41)
01:15:45.432    at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:139)
01:15:45.433    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:132)
01:15:45.433    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
01:15:45.433    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
01:15:45.433    ... 19 more
01:15:45.433 Caused by: org.sonar.squidbridge.api.AnalysisException: SonarQube is unable to analyze file : '/acc1/jenkins/workspace/backend-all-in-one-nightly/prospero-framework/src/main/java/com/accelovation/prospero/cluster/NodeImpl.java'
01:15:45.433    at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:102)
01:15:45.433    at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:75)
01:15:45.434    at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:131)
01:15:45.434    at org.sonar.java.JavaSquid.scan(JavaSquid.java:124)
01:15:45.434    at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:86)
01:15:45.434    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79)
01:15:45.434    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)
01:15:45.434    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:119)
01:15:45.434    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:194)
01:15:45.434    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
01:15:45.434    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
01:15:45.435    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:233)
01:15:45.435    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:228)
01:15:45.435    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:226)
01:15:45.435    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:221)
01:15:45.435    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
01:15:45.435    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
01:15:45.435    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:64)
01:15:45.435    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:51)
01:15:45.435    at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:125)
01:15:45.436    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
01:15:45.436    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
01:15:45.436    at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:173)
01:15:45.436    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
01:15:45.436    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
01:15:45.436    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
01:15:45.436    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
01:15:45.436    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
01:15:45.436    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
01:15:45.437    at java.lang.reflect.Method.invoke(Method.java:606)
01:15:45.437    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
01:15:45.437    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
01:15:45.437    at java.security.AccessController.doPrivileged(Native Method)
01:15:45.437    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
01:15:45.437    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
01:15:45.437    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
01:15:45.437    at org.sonar.runner.api.Runner.execute(Runner.java:100)
01:15:45.437    at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:135)
01:15:45.438    ... 22 more
01:15:45.438 Caused by: java.lang.IndexOutOfBoundsException: index (0) must be less than size (0)
01:15:45.438    at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:301)
01:15:45.438    at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:280)
01:15:45.438    at com.google.common.collect.EmptyImmutableList.get(EmptyImmutableList.java:106)
01:15:45.438    at org.sonar.java.ast.parser.ListTreeImpl.get(ListTreeImpl.java:170)
01:15:45.438    at org.sonar.java.JavaFilesCache.getSuppressWarningArgs(JavaFilesCache.java:185)
01:15:45.438    at org.sonar.java.JavaFilesCache.handleSuppressWarning(JavaFilesCache.java:162)
01:15:45.438    at org.sonar.java.JavaFilesCache.handleSuppressWarning(JavaFilesCache.java:153)
01:15:45.439    at org.sonar.java.JavaFilesCache.visitMethod(JavaFilesCache.java:137)
01:15:45.439    at org.sonar.java.model.declaration.MethodTreeImpl.accept(MethodTreeImpl.java:215)
01:15:45.439    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
01:15:45.439    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
01:15:45.439    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitClass(BaseTreeVisitor.java:69)
01:15:45.439    at org.sonar.java.JavaFilesCache.visitClass(JavaFilesCache.java:110)
01:15:45.439    at org.sonar.java.model.declaration.ClassTreeImpl.accept(ClassTreeImpl.java:199)
01:15:45.439    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
01:15:45.439    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
01:15:45.440    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitClass(BaseTreeVisitor.java:69)
01:15:45.440    at org.sonar.java.JavaFilesCache.visitClass(JavaFilesCache.java:110)
01:15:45.440    at org.sonar.java.model.declaration.ClassTreeImpl.accept(ClassTreeImpl.java:199)
01:15:45.440    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
01:15:45.440    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:37)
01:15:45.440    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitCompilationUnit(BaseTreeVisitor.java:55)
01:15:45.440    at org.sonar.java.model.JavaTree$CompilationUnitTreeImpl.accept(JavaTree.java:136)
01:15:45.440    at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:43)
01:15:45.441    at org.sonar.java.JavaFilesCache.scanFile(JavaFilesCache.java:94)
01:15:45.441    at org.sonar.java.DefaultJavaResourceLocator.scanFile(DefaultJavaResourceLocator.java:126)
01:15:45.441    at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:123)
01:15:45.441    at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:94)
01:15:45.441    ... 59 more
01:15:45.441 [ERROR] 
01:15:45.442 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
01:15:45.442 [ERROR] 
01:15:45.442 [ERROR] For more information about the errors and possible solutions, please read the following articles:
01:15:45.442 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

有人知道为什么会发生这种情况以及如何修复吗?

我们这边已经创建了一个票据来处理这个问题:https://jira.sonarsource.com/browse/SONARJAVA-1233

对于一个类似的问题,问题是由于使用没有参数的非默认SuppressWarnings注释(例如来自findbugs的注释,而不是java.lang.SuppressWarnings),并且没有提供这些类的二进制文件用于分析而引起的。

为分析提供二进制文件应该可以解决这个问题。

最新更新