声纳失败 :[错误] 无法为<类>创建符号表

2022-09-04 20:19:03

当我使用SonarQube 5.6.5运行分析时,我在java源代码上收到以下异常。

我正在用maven项目运行这个分析:
它几乎每个罐子都失败了,但它通过了superpom。我没有写任何源代码,我只是包括sonarqube插件。此错误是由于源代码还是声纳插件引起的?mvn sonar:sonar

Unable to create symbol table for : /Users/dagrawa/EInkReader/apps/ramp/src/com/amazon/ebook/ramp/utils/RAMPUtils.java
java.lang.IllegalArgumentException: null
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:185) ~[sonar-java-plugin-4.15.0.12310.jar:na]
    at org.objectweb.asm.ClassReader.<init>(ClassReader.java:168) ~[sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.resolve.BytecodeCompleter.loadClass(BytecodeCompleter.java:228) ~[sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.resolve.Symbols.<init>(Symbols.java:176) ~[sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.resolve.SemanticModel.createFor(SemanticModel.java:58) ~[sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:101) ~[sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:96) [sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:68) [sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:119) [sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.java.JavaSquid.scan(JavaSquid.java:113) [sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:84) [sonar-java-plugin-4.15.0.12310.jar:na]
    at org.sonar.batch.sensor.SensorWrapper.analyse(SensorWrapper.java:57) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:234) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.task.ScanTask.execute(ScanTask.java:47) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:106) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:79) [sonar-scanner-engine-shaded-5.6.5.jar:na]
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46) [sonar-scanner-api-batch4958703376323836077.jar:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) [sonar-scanner-api-2.10.0.1189.jar:na]
    at com.sun.proxy.$Proxy23.execute(Unknown Source) [na:na]
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171) [sonar-scanner-api-2.10.0.1189.jar:na]
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128) [sonar-scanner-api-2.10.0.1189.jar:na]
    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:63) [sonar-maven-plugin-3.4.0.905.jar:na]
    at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:108) [sonar-maven-plugin-3.4.0.905.jar:na]
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105) [maven-core-3.5.3.jar:3.5.3]
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956) [maven-embedder-3.5.3.jar:3.5.3]
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290) [maven-embedder-3.5.3.jar:3.5.3]
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:194) [maven-embedder-3.5.3.jar:3.5.3]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) [plexus-classworlds-2.5.2.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) [plexus-classworlds-2.5.2.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) [plexus-classworlds-2.5.2.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) [plexus-classworlds-2.5.2.jar:na]

答案 1

我也遇到过类似的问题。这是因为java版本的不兼容性,正如@Ahmed Ashour在前面的答案中所说的那样。在SonarQube中,我们门户,在管理下更新SonarJava插件=>市场=>搜索SonarJava并将其更新到最新版本。然后重新启动SonarQube。

Screenshot for your reference


答案 2

从这里的代码来看,当您的Java版本不符合所需的声纳版本时,就会发生这种情况。

目前的声纳要求是Java 8。

你可以通过以下方式告诉 maven 编译器:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

推荐