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

Resolve.FindMemberType中的java.lang.NullPointerException

狄侯林
2023-03-14

当SonarQube试图分析这段代码时,我有一个NPE:

A.java

public class A<E extends A.B> {
  static class B {}
}
public class C<E> extends A<C.D<E>>{
  static class D<E> extends A.B {}
}
    null
java.lang.NullPointerException: null
  at org.sonar.java.resolve.Resolve.findMemberType(Resolve.java:201) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.Resolve.findType(Resolve.java:222) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.Resolve.findIdent(Resolve.java:282) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:276) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:252) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.resolveType(SecondPass.java:223) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.populateSuperclass(SecondPass.java:123) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.complete(SecondPass.java:89) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.complete(SecondPass.java:60) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.JavaSymbol.complete(JavaSymbol.java:104) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.JavaType.getSymbol(JavaType.java:77) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.visitParameterizedType(TypeAndReferenceSolver.java:350) ~[java-squid-3.4.jar:na]
  at org.sonar.java.model.JavaTree$ParameterizedTypeTreeImpl.accept(JavaTree.java:533) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:285) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:252) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:247) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:321) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.visitParameterizedType(TypeAndReferenceSolver.java:345) ~[java-squid-3.4.jar:na]
  at org.sonar.java.model.JavaTree$ParameterizedTypeTreeImpl.accept(JavaTree.java:533) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:285) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:252) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.resolveType(SecondPass.java:223) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.populateSuperclass(SecondPass.java:123) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.complete(SecondPass.java:89) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SecondPass.complete(SecondPass.java:60) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.JavaSymbol.complete(JavaSymbol.java:104) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.FirstPass.completeSymbols(FirstPass.java:90) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.FirstPass.visitCompilationUnit(FirstPass.java:121) ~[java-squid-3.4.jar:na]
  at org.sonar.java.resolve.SemanticModel.createFor(SemanticModel.java:67) ~[java-squid-3.4.jar:na]
  at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:110) ~[java-squid-3.4.jar:na]
  at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:94) [java-squid-3.4.jar:na]
  at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:75) [java-squid-3.4.jar:na]
  at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:131) [java-squid-3.4.jar:na]
  at org.sonar.java.JavaSquid.scan(JavaSquid.java:124) [java-squid-3.4.jar:na]
  at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:86) [sonar-java-plugin-3.4.jar:na]
  at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:59) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:51) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.phases.DatabaseModePhaseExecutor.execute(DatabaseModePhaseExecutor.java:120) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:264) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:220) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:135) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:158) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67) [sonar-batch-maven-compat-5.1.2.jar:na]
  at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48) [sonar-runner-batch1248517138931767319.jar:na]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60-ea]
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60-ea]
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60-ea]
  at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60-ea]
  at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87) [sonar-runner-api-2.4.jar:na]
  at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75) [sonar-runner-api-2.4.jar:na]
  at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_60-ea]
  at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) [sonar-runner-api-2.4.jar:na]
  at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) [sonar-runner-api-2.4.jar:na]
  at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102) [sonar-runner-api-2.4.jar:na]
  at org.sonar.runner.api.Runner.execute(Runner.java:100) [sonar-runner-api-2.4.jar:na]
  at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:135) [sonar-maven-plugin-2.6.jar:na]
  at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:132) [sonar-maven-plugin-2.6.jar:na]
  at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155) [maven-core-3.2.5.jar:3.2.5]
  at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584) [maven-embedder-3.2.5.jar:3.2.5]
  at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216) [maven-embedder-3.2.5.jar:3.2.5]
  at org.apache.maven.cli.MavenCli.main(MavenCli.java:160) [maven-embedder-3.2.5.jar:3.2.5]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60-ea]
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60-ea]
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60-ea]
  at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60-ea]
  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个答案

孙嘉
2023-03-14

感谢您提供了精确的代码段。我在我这边重现了这个问题,看来Sonarqube java插件在这种情况下确实存在参数化类型的类型解析问题。感谢您提供的信息,我创建了以下票证来处理该问题:http://jira.sonarsource.com/browse/sonarjava-1218

 类似资料:
  • 我觉得我应该给出一个代码的概念。我遇到了这个问题,我需要编写两个函数,一个是find(),如果它在给定字符串中找到子字符串的索引,它将返回一个布尔值。该函数应该“在索引数组中保存索引值”。另一个方法是replace(),它用新单词替换所有搜索的单词,然后输出新字符串。需要输出匹配词的索引号。 现在的问题是,我在注释行处发现nullpointer异常。你能告诉我问题出在哪里吗?我搜索错误无济于事。

  • 我使用子JPanel构造JScrollPane,然后尝试将JScrollPane添加到父JPanel中,希望有一个可滚动的自定义JPanel。 我有一个大的细白线前面的所有我的组件,他们是没有滚动。有什么想法吗?

  • 我有一个HQL查询,通过传递一个列表来检查某些细节!精确的数组列表。下面是HQL查询。 下面是我用来传输两个参数数组列表的代码。 对于给定的参数,我从getQuery行中得到一个空指针异常!在第一次运行时,search chCriteria参数为空,因此其他参数将被执行!我不知道空指针异常发生在哪里! 非常感谢。 这是我的堆栈跟踪!

  • 我已经为android Studio创建了一个webview应用程序。但没有加载web URL。错误为NET::ERR_ACCESS_DENIED。有谁能帮忙吗

  • 2017/08/17 16:57:42 ERROR-jmeter.save.saveService:转换错误com.thoughtworks.xstream.conversionexception:com.atlantbh.jmeter.plugins.jsonutils.jsonpathextractor.jsonpathextractor:com.atlantbh.jmeter.jsonuti

  • 我有一个使用Java Version8的Spring和Maven的项目。当我运行maven update时,它适用于Java9或更高版本,当我编译它时,它适用于Java8。我注意到了这一点,因为用Maven更新会将一个特定的类更改为Java9,而我无法导入这个类。 这个类是:javax.annotation.generated(Java8)。 这是要导入的类。但是,当我进行maven更新时,文件的