当前位置: 首页 > 知识库问答 >
问题:

运行声纳扫描仪时出错

钱凌
2023-03-14

声纳扫描仪在运行扫描仪时抛出空指针异常。错误指向一个枚举。它实现了一个典型的接口。

我记得几个月前运行扫描仪时没有出现任何问题,但这次不同了,感谢您的帮助。

public enum ItsAnEnum implements SomeField<SomeEnumModuleType> {

public interface SomeField<T extends CodeEnum> extends NumericEnumWithLabel, CodeEnumWithLabel {

ERROR: Error during SonarQube Scanner execution
org.sonar.squidbridge.api.AnalysisException: SonarQube is unable to analyze file : 'C:\opt\workspace\project\src\main\package\ItsAnEnum.java'
        at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:93)
        at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:67)
        at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:114)
        at org.sonar.java.JavaSquid.scan(JavaSquid.java:108)
        at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:87)
        at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
        at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:57)
        at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:49)
        at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:182)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:247)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:242)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:232)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
        at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
        at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
        at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:115)
        at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:116)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)
        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:483)
        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:233)
        at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
        at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.NullPointerException
        at org.sonar.java.checks.PrivateFieldUsedLocallyCheck.containingClassOrMethod(PrivateFieldUsedLocallyCheck.java:125)
        at org.sonar.java.checks.PrivateFieldUsedLocallyCheck.usedInOneMethodOnly(PrivateFieldUsedLocallyCheck.java:105)
        at org.sonar.java.checks.PrivateFieldUsedLocallyCheck.checkPrivateField(PrivateFieldUsedLocallyCheck.java:78)
        at org.sonar.java.checks.PrivateFieldUsedLocallyCheck.lambda$visitNode$4(PrivateFieldUsedLocallyCheck.java:70)
        at org.sonar.java.checks.PrivateFieldUsedLocallyCheck$$Lambda$79/1947060963.accept(Unknown Source)
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
        at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
        at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
        at org.sonar.java.checks.PrivateFieldUsedLocallyCheck.visitNode(PrivateFieldUsedLocallyCheck.java:70)
        at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:95)
        at org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:120)
        at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)
        at org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:120)
        at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)
        at org.sonar.java.ast.visitors.SubscriptionVisitor.scanTree(SubscriptionVisitor.java:78)
        at org.sonar.java.ast.visitors.SubscriptionVisitor.scanFile(SubscriptionVisitor.java:64)
        at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:121)
        at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:84)
        ... 34 more
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

添加了一些乱码,我可以保证没有编译问题。

package com.some.package;

import java.util.HashMap;
import java.util.Map;



public enum ModuleEnumField implements RouteSelField<SomeModuleType> {

    BUYER(1, "something", "something", SomeEnum.STRING, "", SomeEnum.ORDER),
    TERMS(2, "something", "something", SomeEnum.DETAIL_STRING, "", SomeEnum.ORDER)

    private int number;
    private String label;
    private SomeEnum type;
    private String extraInfo;
    private String moduleInfo;
    private SomeEnum moduleType;
    private String tableName;
    private String columnName;

    private ModuleEnumField(int number, String tableName, String columnName, SomeEnum type, String extraInfo, SomeModuleType moduleType) {
        this.number = number;
        this.tableName = tableName;
        this.columnName = columnName;
        this.label = tableName + "." + columnName;
        this.type = type;
        this.extraInfo = extraInfo;
        this.moduleInfo = moduleType.getLabel();
        this.moduleType = moduleType;
        ModuleEnumFieldMaps.numericMapping.put(number, this);
        ModuleEnumFieldMaps.codeMapping.put(label, this);
    }

    @Override
    public String getLabel() {
        return label;
    }

    @Override
    public int getNumber() {
        return number;
    }

    @Override
    public String getExtraInfo() {
        return extraInfo;
    }

    @Override
    public String getModuleInfo() {
        return moduleInfo;
    }

    @Override
    public SomeModuleType getModuleType() {
        return moduleType;
    }

    @Override
    public SomeEnum getFieldType() {
        return type;
    }


    @Override
    public String getCode() {
        return label;
    }


    public static ModuleEnumField getFieldByNumber(int number) {
        return ModuleEnumFieldMaps.numericMapping.get(number);
    }

    public static ModuleEnumField getFieldByCode(String code) {
        return ModuleEnumFieldMaps.codeMapping.get(code);
    }

    private static class ModuleEnumFieldMaps {
        private static Map<Integer, ModuleEnumField> numericMapping = new HashMap<Integer, ModuleEnumField>();
        private static Map<String, ModuleEnumField> codeMapping = new HashMap<String, ModuleEnumField>();
    }

    public String getTableName() {
        return tableName;
    }

    public String getColumnName() {
        return columnName;
    }

}

包括声纳项目属性。#所需元数据sonar.project密钥=com.companysonar.project名称=项目sonar.project版本=1.0

sonar.sources=src
sonar.java.binaries=target/classes

# java version used by source files:
sonar.java.source=1.8

共有1个答案

牟黎昕
2023-03-14

为了防止搜索旧的bug,您应该始终使用SonarQube LTS版本以及该版本的最新兼容插件和扫描仪。这些项目定期更新。例如,请参阅SonarScanner for MSBuild和插件版本矩阵的兼容性页面。你可以使用版本矩阵页面上的链接来获取插件的详细信息。

 类似资料:
  • 我尝试使用Jenkins上的java项目运行声纳分析,使用标准的maven sonar:sonar goal,并使用post STEP>>Execute SonarQube Scanner。我使用的maven目标是。 对于SonarQube扫描仪,我使用了下面的maven目标 SonarQube版本-7.7声纳扫描仪版本-3.3.0 Jenkins版本-2.164.3 Maven版本-3.6.1

  • 我有一个CI工作流,它集成了一个linting作业和一个代码质量作业。我的Linting工作是docker runner从应用程序代码启动我的eslint脚本。然后,我的代码质量工作应该是启动一个sonar scanner docker实例,检查我的代码并将报告发送回sonarqube实例。 问题主要在于我无法使用以下两种解决方案正确启动声纳扫描仪: Sonar Scanner Dockerhtt

  • 我有java项目(非梯度),想要测试Sonarqube。所以,我安装了sonar-scanner for mac(https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/)我如何使用它扫描我的Java项目? 我的项目结构是:src->main-java->COM->MyCompany>PackageName1->[java文件]sr

  • 我正在为这个项目做准备。大约一个月前,我成功地配置了它,但在那里我遇到了一个错误。这个错误可能发生在Sonarqube之外的其他事情上,所以如果你知道如何解决它,我就是一个接受者。错误是当我在我的项目文件夹中运行命令:“sonar scanner”时。 VM初始化时出错 java/lang/NoClassDefFoundError:java/lang/Object 我试过: 重启我的电脑(LOL)

  • 我试图将Sonar Scanner for Ms Build与Teamcity集成。但是在完成分析步骤中存在问题。我配置了SonarQube。Sonarqube网站上显示的带有sonar.login、sonar.password和sonar.host.url的nalysis.xml文件。但是它给出了错误。 SonarQube开始分析步骤 SonarQube完成分析步骤 错误日志 我尝试重新启动服务