升级到SonarQube 4.2后,在Jenkins / Maven分析中进行NPE

时间:2014-04-08 13:21:26

标签: maven jenkins sonarqube

经过一段时间后,分析会抛出NPE。但它不是它分析的第一个模块。所以我没有线索,问题可能是什么。使用SonarQube 4.1.2,它没有问题。

这里注销NPE:

15:06:41 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.2:sonar (default-    cli) on project XXX: Can not execute SonarQube analysis
15:06:41    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
15:06:41    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
15:06:41    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
15:06:41    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
15:06:41    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
15:06:41    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
15:06:41    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
15:06:41    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
15:06:41    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
15:06:41    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
15:06:41    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
15:06:41    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
15:06:41    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:06:41    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
15:06:41    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:06:41    at java.lang.reflect.Method.invoke(Method.java:601)
15:06:41    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
15:06:41    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
15:06:41    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
15:06:41    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
15:06:41 Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute SonarQube analysis
15:06:41    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:109)
15:06:41    at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:67)
15:06:41    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:109)
15:06:41    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
15:06:41    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
15:06:41    ... 19 more
15:06:41 Caused by: org.apache.maven.plugin.MojoExecutionException
15:06:41    at org.sonar.maven.ExceptionHandling.handle(ExceptionHandling.java:37)
15:06:41    at org.sonar.maven.SonarMojo.execute(SonarMojo.java:175)
15:06:41    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:104)
15:06:41    ... 23 more
15:06:41 Caused by: java.lang.NullPointerException
15:06:41    at org.sonar.plugins.java.bridges.DsmSerializer.serializeCell(DsmSerializer.java:86)
15:06:41    at org.sonar.plugins.java.bridges.DsmSerializer.serializeRow(DsmSerializer.java:74)
15:06:41    at org.sonar.plugins.java.bridges.DsmSerializer.serializeRows(DsmSerializer.java:53)
15:06:41    at org.sonar.plugins.java.bridges.DsmSerializer.serialize(DsmSerializer.java:43)
15:06:41    at org.sonar.plugins.java.bridges.DsmSerializer.serialize(DsmSerializer.java:94)
15:06:41    at org.sonar.plugins.java.bridges.DesignBridge.serializeDsm(DesignBridge.java:133)
15:06:41    at org.sonar.plugins.java.bridges.DesignBridge.onProject(DesignBridge.java:83)
15:06:41    at org.sonar.plugins.java.Bridges.saveProject(Bridges.java:76)
15:06:41    at org.sonar.plugins.java.Bridges.save(Bridges.java:67)
15:06:41    at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:87)
15:06:41    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79)
15:06:41    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)
15:06:41    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:134)
15:06:41    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:186)
15:06:41    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
15:06:41    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
15:06:41    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:199)
15:06:41    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:194)
15:06:41    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:192)
15:06:41    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:192)
15:06:41    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:187)
15:06:41    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
15:06:41    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
15:06:41    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:56)
15:06:41    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:44)
15:06:41    at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:82)
15:06:41    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
15:06:41    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
15:06:41    at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:144)
15:06:41    at org.sonar.batch.bootstrap.BootstrapContainer.doAfterStart(BootstrapContainer.java:132)
15:06:41    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
15:06:41    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
15:06:41    at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:92)
15:06:41    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:74)
15:06:41    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45)
15:06:41    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:06:41    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
15:06:41    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:06:41    at java.lang.reflect.Method.invoke(Method.java:601)
15:06:41    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
15:06:41    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
15:06:41    at java.security.AccessController.doPrivileged(Native Method)
15:06:41    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
15:06:41    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
15:06:41    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
15:06:41    at org.sonar.runner.api.Runner.execute(Runner.java:90)
15:06:41    at org.sonar.maven.SonarMojo.execute(SonarMojo.java:173)
15:06:41    ... 24 more

3 个答案:

答案 0 :(得分:1)

创建了JIRA票证:http://jira.codehaus.org/browse/SONARJAVA-501优先级为" Blocker"

答案 1 :(得分:0)

基于this thread,似乎是插件无法与SonarCube 4.2保持同步的问题。似乎这些变化不向后兼容。

最新版本的Jenkins插件是2.1。它于2013年发布,由于SonarCube 4.2仅为released a month ago,因此看起来需要发布新版本的插件才能实现。

答案 2 :(得分:0)

仅供记录并提供更完整的答案:

问题是由于你的项目目录中有一些Java文件定义了多个包:

directory  : foo 
                file A.java : 
                           package foo;
                           class A {.... 

                file B.java
                           package bar;
                           class B { .... 

这完全由javac支持,但这是一个不好的做法,它通过声纳-java分析检测并引发警告: "目录包含属于不同包的文件 - 某些指标可能报告错误:..."

如果B类在另一个目录中引用项目的其他一些类,那么它将引发您面临的空指针异常。 在sonar-java 2.2中实现的修复是在没有skipDesign标志以使分析失败并邀请您修复源代码或使用skipPackageDesign标志的情况下引发特定异常

您可能会问的一个问题是为什么在SQ 4.2和sonar-java 2.1之前工作:这是有效的,因为Java是SonarQube所涵盖语言的特定公民,并使用了一个名为JavaPackage的特定对象。 我们在SQ 4.2和sonar-java 2.1中摆脱了这种特殊性,因此如果在一个目录中有多个包,我们将无法再正确地附加指标。在你提出的情况下,我们甚至无法生成依赖图。

因此,解决方案是通过将文件放入与其包对应的目录中来修复代码,或者使用已经提到的标志跳过此依赖性分析。

我们在即将推出的sonar-java 2.2中为此提供了更好的错误处理。