java.lang.NullPointerException in Resolve.findMemberType

I have a NPE when SonarQube try to analyze this code:

A.java

public class A<E extends A.B> {
  static class B {}
}

C.java

public class C<E> extends A<C.D<E>>{
  static class D<E> extends A.B {}
}

Context :

  • SonarQube 5.1.2
  • Sonar-java-plugin-3.4
  • Maven 3.2.5 (mvn sonar:sonar)

Stack :

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]

Answers


Thank you for providing a precise code snippet. I reproduced the issue on my side and it seems that the SonarQube java plugin indeed have an issue with type resolution of parameterized types in such situations. Thanks to the information you provided, I created the following ticket to handle the issue: http://jira.sonarsource.com/browse/SONARJAVA-1218


Need Your Help

Tomcat 6 Clustering - Authenticated Session Replication

jsf tomcat cluster-computing mod-proxy session-replication

I currently have a very basic cluster composed of two Tomcat 6.0.32 instances (Tomcat1 and Tomcat2) running on the same VPS. I'm using mod_proxy_ajp and mod_proxy_balancer as the load balancer thro...