【问题标题】:Get NullPointerException while running sonarqube analysis of my code在对我的代码运行声纳分析时获取 NullPointerException
【发布时间】:2016-01-07 19:27:22
【问题描述】:

我有一份 Jenkins 工作,将单元测试覆盖率(lcov 格式)发布到 SonarQube 服务器,如question 及其答案中所述。有时,我会在 Jenkins 控制台日志的 node_modules 目录中看到以下 JavaScript 文件异常。

16:57:15.037 ERROR - Problem while calculating coverage for /var/lib/jenkins/jobs/jenkins-project-name/workspace/project-name/node_modules/js-tokens/test/fixtures/regex.js
java.lang.NullPointerException: null
at org.sonar.plugins.javascript.lcov.UTCoverageSensor.saveZeroValueForResource(UTCoverageSensor.java:146) [sonar-javascript-plugin-2.9.jar:na]
at org.sonar.plugins.javascript.lcov.UTCoverageSensor.saveMeasureFromLCOVFile(UTCoverageSensor.java:128) [sonar-javascript-plugin-2.9.jar:na]
at org.sonar.plugins.javascript.lcov.UTCoverageSensor.analyse(UTCoverageSensor.java:85) [sonar-javascript-plugin-2.9.jar:na]
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:98) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:258) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:253) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:243) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.bootstrap.GlobalContainer.executeAnalysis(GlobalContainer.java:153) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:110) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:76) [sonar-batch-shaded-5.2.jar:na]
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48) [sonar-runner-batch8900787800742033772.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79]
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75) [sonar-runner-dist-2.4.jar:na]
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_79]
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.api.Runner.execute(Runner.java:100) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.executeTask(Main.java:70) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.execute(Main.java:59) [sonar-runner-dist-2.4.jar:na]
at org.sonar.runner.Main.main(Main.java:53) [sonar-runner-dist-2.4.jar:na]

我将node_modules 目录添加到排除列表中:

sonar.exclusions=./project-name/node_modules/**/*
sonar.test.exclusions=./project-name/node_modules/**/*

但我仍然有时会收到错误消息。知道有什么问题吗?

【问题讨论】:

    标签: node.js jenkins sonarqube node-modules


    【解决方案1】:

    您的情况似乎类似于known issue,它将在 JavaScript 插件的 2.10 版中修复。这个版本应该会在未来几天内发布。

    作为一种解决方法,您应该可以设置排除项。如果仍然出现同样的错误,我认为 SonarQube 未正确解析您提供的路径:您可以尝试在开头删除 ./

    【讨论】:

    • 在开头删除./ 为我解决了这个问题。谢谢
    猜你喜欢
    • 1970-01-01
    • 2015-10-24
    • 2016-07-05
    • 2013-01-13
    • 2011-04-03
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    相关资源
    最近更新 更多