Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-2279

SonarJava fails to parse files with a BOM

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.9
    • Fix Version/s: None
    • Component/s: Plugin
    • Labels:
      None

      Description

      SonarJava fails to parse files with a BOM.

      [ERROR] Unable to parse source file : /home/julien/Prog/Projects/plugins/sonar-groovy/sonar-groovy-plugin/src/main/java/org/sonar/plugins/groovy/GroovySensor.java 
      [ERROR] Parse error at line 1 column 1: 
      
      1: ��/* 
         ^ 
      2:  * Sonar Groovy Plugin 
      3:  * Copyright (C) 2010-2016 SonarSource SA 
      4:  * mailto:contact AT sonarsource DOT com
      

      We have to ensure to exclude BOM when reading file content. It can easily be done using BOMInputStream from commons-io.

      Note1: Starting from SonarQube 6.4, it will automatically be done when calling InputFile::content or InputFile::inputStream. For all the versions of SQ prior to 6.3, the analysis will fail when encountering BOM, even when relying on SonarQube 6.3 and 6.2 API to retrieve file content. It means that once new LTS will be released, the issue will solve by itself.

      Note2: Once corrected on SonarJava side, and as long as new LTS is not released, the analysis will continue to fail, but this time on CPD side (platform side). The case being not handled there as well. Fixing the issue on SonarJava is therefore not of high priority (except in case of community feedback).

      Source code causing the issue: https://github.com/SonarSource/sonar-java/blob/4.9.0.9858/java-frontend/src/main/java/org/sonar/java/SonarComponents.java#L249

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              michael.gumowski Michael Gumowski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: