运行声纳扫描仪时出错

时间:2017-02-19 16:46:14

标签: java sonarqube

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

我记得几个月前运行扫描仪没有任何问题,但这次它有所不同,任何帮助都表示赞赏。

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.projectKey = com.company     sonar.projectName =项目     sonar.projectVersion = 1.0

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

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

1 个答案:

答案 0 :(得分:1)

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