Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-9574

The same file should not belong to different modules

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.6-M1, 6.6
    • Component/s: Scanner
    • Labels:
      None

      Description

      If a file is given in the sources of 2 modules it will get indexed and processed twice, even if it is in fact the same file.

      To reproduce, create a multimodule project with the following structure:

      Root
      -- M1
      

      and a single file `src/File.java` in M1.

      Then create the following configuration (sonar-project.properties):

      sonar.projectKey=sonar-9574
      
      M1.sonar.sources=src/File.java
      
      sonar.modules=M1
      sonar.sources=M1/src/File.java
      

      Sensors running in each module

      The file `File.java` will end up being indexed in both `Root` and `M1`, and processed by analyzers in each modules as if there were 2 different files.
      The same file will appear twice in SonarQube, once in each module (see screenshot).

      Global sensors

      Global sensors using predicates by path in the Sensor API to get files should be OK because they will see only the the latest version of the file that was indexed (the one belonging to the root module). However, this means that in SonarQube we will probably see a file belonging to the root module instead of a file belonging to the more specific child module (see screenshot).

      The cpp plugin will fail because it first fetches all files by language (getting both versions of the file), and then querying again to get the InputFile by absolute path (which returns always the latest indexed version of it). It ends up trying to create highlighting twice for the same InputFile:

      15:46:27.375 ERROR: Error during SonarQube Scanner execution
      java.lang.UnsupportedOperationException: Trying to save highlighting twice for the same file is not supported: C:/xxxxx/Source.cpp
              at org.sonar.scanner.sensor.DefaultSensorStorage.store(DefaultSensorStorage.java:372)
              at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.doSave(DefaultHighlighting.java:121)
              at org.sonar.api.batch.sensor.internal.DefaultStorable.save(DefaultStorable.java:45)
              at com.sonar.cpp.plugin.LexicalAnalyzer.highlight(LexicalAnalyzer.java:159)
              at com.sonar.cpp.plugin.LexicalAnalyzer.analyze(LexicalAnalyzer.java:68)
              at com.sonar.cpp.plugin.LexicalAnalyzer.analyze(LexicalAnalyzer.java:60)
              at com.sonar.cpp.plugin.CFamilySquidSensor.execute(CFamilySquidSensor.java:202)
              at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
              at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
              at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
              at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:73)
              at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
              at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:179)
              at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
              at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
              at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:261)
              at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:256)
              at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:245)
              at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
              at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
              at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
              at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
              at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
              at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
              at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:119)
              at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:116)
              at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
              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.$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:123)
              at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
              at org.sonarsource.scanner.cli.Main.main(Main.java:61)
      15:46:27.381 ERROR:
      15:46:27.381 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
      

      Solution

      We should fail fast once we detect that a file was already indexed while executing a previous module. This can probably be easily done when adding it to the global file index.

        Attachments

        1. ss.png
          11 kB
          Duarte Meneses

          Issue Links

            Activity

              People

              Assignee:
              julien.henry Julien Henry
              Reporter:
              duarte.meneses Duarte Meneses
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: