NullPointerException -> Unable to create symbol table

java

(Hylke van der Schaaf) #1

Template for a good bug report, formatted with Markdown:

  • versions used: A fresh 7.4 and the version used on Travis
  • error observed: see below for stack trace.
  • steps to reproduce:
  • potential workaround: None that I know of.

Full travis output can be found at https://travis-ci.org/FraunhoferIOSB/FROST-Server/jobs/454040480
The exception happens at line 6235.

[ERROR] Unable to create symbol table for : /home/scf/NetBeansProjects/SensorThings/FROST-Server/FROST-Server.SQL/src/main/java/de/fraunhofer/iosb/ilt/sta/persistence/postgres/PostgresPersistenceManager.java
java.lang.NullPointerException: null
	at org.sonar.java.resolve.TypeSubstitutionSolver.applySubstitution(TypeSubstitutionSolver.java:210)
	at org.sonar.java.resolve.TypeSubstitutionSolver.applySiteSubstitution(TypeSubstitutionSolver.java:175)
	at org.sonar.java.resolve.Resolve.findField(Resolve.java:134)
	at org.sonar.java.resolve.Resolve.findIdentInType(Resolve.java:360)
	at org.sonar.java.resolve.FirstPass$ImportResolverVisitor.visitIdentifier(FirstPass.java:210)
	at org.sonar.java.model.expression.IdentifierTreeImpl.accept(IdentifierTreeImpl.java:81)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitMemberSelectExpression(BaseTreeVisitor.java:229)
	at org.sonar.java.model.expression.MemberSelectExpressionTreeImpl.accept(MemberSelectExpressionTreeImpl.java:115)
	at org.sonar.java.resolve.FirstPass$ImportResolverVisitor.visitImport(FirstPass.java:168)
	at org.sonar.java.model.JavaTree$ImportTreeImpl.accept(JavaTree.java:351)
	at org.sonar.java.resolve.FirstPass.resolveImports(FirstPass.java:154)
	at org.sonar.java.resolve.FirstPass.visitCompilationUnit(FirstPass.java:131)
	at org.sonar.java.resolve.SemanticModel.createFor(SemanticModel.java:65)
	at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:109)
	at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:96)
	at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:68)
	at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:116)
	at org.sonar.java.JavaSquid.scan(JavaSquid.java:110)
	at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:93)
	at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:45)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:88)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:62)
	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:164)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:319)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:314)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:312)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:288)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)
	at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	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:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy23.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
	at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:65)
	at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:104)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	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:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

(Michael Gumowski) #2

Hey @hylkevds,

Thanks for the feedback and the link to the project to reproduce the issue. It helped me to identify the problem and reduce the case to the following self-contained reproducer:

package org.foo;

import static org.foo.A.BAR;

public class A<X> {
  public static final String BAR = "value";
}

Consequently, I created the following JIRA ticket to handle it: SONARJAVA-2964

While this is absolutely a bug that we will need to fix, note that you can probably workaround the issue in the file by removing the static import of the TAG_DATA_SOURCE constant, declared at line 38. It seems useless to me as well.

import static de.fraunhofer.iosb.ilt.sta.persistence.postgres.PostgresPersistenceManager.TAG_DATA_SOURCE;

Cheers,
Michael


(Hylke van der Schaaf) #3

Thanks! Great that you found the bug. That superfluous import must’ve crept in during refactoring.
I guess that’s also a new potential Sonar rule: superfluous import!


(Michael Gumowski) #4

Hey,

Indeed, let’s learn from this and improve everywhere we can! :slight_smile:

Note that because of the symbol table error, the file was anyway skipped during analysis and not a single java rule was played against it.

Now, we already have a rule which targets useless imports (S1128 or squid:UselessImportsCheck). However this case should be handled and the rule improved to cover it. I consequently created the following ticket to improve its implementation: SONARJAVA-2965

Thanks again for your feedback!
Michael