当使用不带参数的 lambda 时,Sonarqube Java 分析器在代码分析期间抛出 NullPointerException
The Sonarqube Java analyser throws NullPointerException during code analysis, when using lambdas without arguments
Sonarqube(版本 5.1.1,带有 Java-Plugin 版本 3.3 和 Maven-Sonar-Plugin 版本 2.6)在代码分析期间因 NPE 而崩溃。
当您使用不带参数的 Lambda 时,这似乎会发生。
这是该案例的代码示例:
import java.util.stream.*;
import java.util.*;
public class Foobar {
public Object foobar() {
return Arrays
.asList("1", "2", "3")
.stream()
.findFirst()
.orElseGet(() -> "FOOBAR");
}
}
Java-插件还不支持这些表达式吗?
关于如何在不排除所有此类 类 的情况下解决该问题的想法?
编辑 - 这是堆栈跟踪:
Unable to analyze .class file Foobar
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
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:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to analyze .class file Foobar
at org.codehaus.mojo.sonar.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:41)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:139)
at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:132)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: org.sonar.squidbridge.api.AnalysisException: Unable to analyze .class file Foobar
at org.sonar.java.bytecode.BytecodeScanner.notifyBytecodeVisitors(BytecodeScanner.java:82)
at org.sonar.java.bytecode.BytecodeScanner.scanClasses(BytecodeScanner.java:60)
at org.sonar.java.bytecode.BytecodeScanner.scan(BytecodeScanner.java:51)
at org.sonar.java.JavaSquid.scanBytecode(JavaSquid.java:146)
at org.sonar.java.JavaSquid.scan(JavaSquid.java:126)
at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:86)
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:59)
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:51)
at org.sonar.batch.phases.DatabaseModePhaseExecutor.execute(DatabaseModePhaseExecutor.java:120)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:264)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:220)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57)
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45)
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:135)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:158)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
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:497)
at org.sonar.runner.impl.BatchLauncher.delegateExecution(BatchLauncher.java:87)
at org.sonar.runner.impl.BatchLauncher.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:135)
... 22 more
Caused by: java.lang.NullPointerException
at org.sonar.java.signature.ParameterSignaturePrinter.print(ParameterSignaturePrinter.java:28)
at org.sonar.java.signature.MethodSignaturePrinter.print(MethodSignaturePrinter.java:32)
at org.sonar.java.bytecode.visitor.BytecodeVisitor.getMethodLineNumber(BytecodeVisitor.java:69)
at org.sonar.java.checks.RedundantThrowsDeclarationCheck.visitMethod(RedundantThrowsDeclarationCheck.java:57)
at org.sonar.java.bytecode.BytecodeVisitorNotifier.callVisitMethod(BytecodeVisitorNotifier.java:74)
at org.sonar.java.bytecode.BytecodeVisitorNotifier.callVisitMethodAndFieldAndEdge(BytecodeVisitorNotifier.java:55)
at org.sonar.java.bytecode.BytecodeVisitorNotifier.notifyVisitors(BytecodeVisitorNotifier.java:48)
at org.sonar.java.bytecode.BytecodeScanner.notifyBytecodeVisitors(BytecodeScanner.java:80)
... 59 more
@benzonico
谢谢你的提示。我们使用的是 eclipse 编译器,它恰好不是最新版本并导致了问题。
对于其他有类似问题的人:
您需要在您的 maven-poms 中使用以下组合:
org.eclipse.tycho:tycho-compiler-jdt:0.23.0
org.eclipse.tycho:org.eclipse.jdt.core:3.11.0.v20150520-2033
Sonarqube(版本 5.1.1,带有 Java-Plugin 版本 3.3 和 Maven-Sonar-Plugin 版本 2.6)在代码分析期间因 NPE 而崩溃。
当您使用不带参数的 Lambda 时,这似乎会发生。
这是该案例的代码示例:
import java.util.stream.*;
import java.util.*;
public class Foobar {
public Object foobar() {
return Arrays
.asList("1", "2", "3")
.stream()
.findFirst()
.orElseGet(() -> "FOOBAR");
}
}
Java-插件还不支持这些表达式吗?
关于如何在不排除所有此类 类 的情况下解决该问题的想法?
编辑 - 这是堆栈跟踪:
Unable to analyze .class file Foobar
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
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:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to analyze .class file Foobar
at org.codehaus.mojo.sonar.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:41)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:139)
at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:132)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: org.sonar.squidbridge.api.AnalysisException: Unable to analyze .class file Foobar
at org.sonar.java.bytecode.BytecodeScanner.notifyBytecodeVisitors(BytecodeScanner.java:82)
at org.sonar.java.bytecode.BytecodeScanner.scanClasses(BytecodeScanner.java:60)
at org.sonar.java.bytecode.BytecodeScanner.scan(BytecodeScanner.java:51)
at org.sonar.java.JavaSquid.scanBytecode(JavaSquid.java:146)
at org.sonar.java.JavaSquid.scan(JavaSquid.java:126)
at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:86)
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:59)
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:51)
at org.sonar.batch.phases.DatabaseModePhaseExecutor.execute(DatabaseModePhaseExecutor.java:120)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:264)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:220)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57)
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45)
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:135)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:158)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
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:497)
at org.sonar.runner.impl.BatchLauncher.delegateExecution(BatchLauncher.java:87)
at org.sonar.runner.impl.BatchLauncher.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:135)
... 22 more
Caused by: java.lang.NullPointerException
at org.sonar.java.signature.ParameterSignaturePrinter.print(ParameterSignaturePrinter.java:28)
at org.sonar.java.signature.MethodSignaturePrinter.print(MethodSignaturePrinter.java:32)
at org.sonar.java.bytecode.visitor.BytecodeVisitor.getMethodLineNumber(BytecodeVisitor.java:69)
at org.sonar.java.checks.RedundantThrowsDeclarationCheck.visitMethod(RedundantThrowsDeclarationCheck.java:57)
at org.sonar.java.bytecode.BytecodeVisitorNotifier.callVisitMethod(BytecodeVisitorNotifier.java:74)
at org.sonar.java.bytecode.BytecodeVisitorNotifier.callVisitMethodAndFieldAndEdge(BytecodeVisitorNotifier.java:55)
at org.sonar.java.bytecode.BytecodeVisitorNotifier.notifyVisitors(BytecodeVisitorNotifier.java:48)
at org.sonar.java.bytecode.BytecodeScanner.notifyBytecodeVisitors(BytecodeScanner.java:80)
... 59 more
@benzonico 谢谢你的提示。我们使用的是 eclipse 编译器,它恰好不是最新版本并导致了问题。
对于其他有类似问题的人: 您需要在您的 maven-poms 中使用以下组合:
org.eclipse.tycho:tycho-compiler-jdt:0.23.0
org.eclipse.tycho:org.eclipse.jdt.core:3.11.0.v20150520-2033