3

I have this error message when running SonarQube on a C# project :

...

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 30.377s
INFO: Final Memory: 58M/828M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalArgumentException: 79 is not a valid line offset for pointer. File [moduleKey=dot-net_SCHLUMBERGER-Helios, relative=wtap_nextgen/Src/Component/WebSolution/MMS/wwwroot/css/bootwatch-paper.css, basedir=/builds/dot-net/SCHLUMBERGER-Helios] has 78 character(s) at line 1
    at org.sonar.api.internal.google.common.base.Preconditions.checkArgument(Preconditions.java:148)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.checkValid(DefaultInputFile.java:218)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.newPointer(DefaultInputFile.java:209)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange(DefaultInputFile.java:240)
    at org.sonar.css.issue.PreciseIssue.save(PreciseIssue.java:119)
    at org.sonar.plugins.css.CssSquidSensor.saveIssues(CssSquidSensor.java:121)
    at org.sonar.plugins.css.CssSquidSensor.save(CssSquidSensor.java:105)
    at org.sonar.plugins.css.CssSquidSensor.analyse(CssSquidSensor.java:89)
    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50)
    at org.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83)
    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236)
    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.batch.task.ScanTask.execute(ScanTask.java:47)
    at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
    at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:106)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)
    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:240)
    at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
    at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:72)
    at org.sonarsource.scanner.cli.Main.main(Main.java:60)

ERROR: Build failed: exit code 1

Does anyone have a clue where this comes from ? It seems like the scanner is trying to access character 79 of the first line of XXX/bootwatch-paper.css, which only has 78 characters. Why would it try to read the 79th character ? Could this be an encoding issue? How to fix this ?

Cheers!

fleuryc
  • 493
  • 7
  • 24
  • You should create a topic in the Google Group https://groups.google.com/forum/#!forum/sonarqube – CSchulz Jun 23 '16 at 07:50

2 Answers2

2

I had a similar issue with one of my AssemblyInfo.cs files. It was definitely the encoding. I opened the file in Sublime Text and saved it with different encodings to see what worked. Here is what I found, although it may be different for you since I was using the C# plugin and you are using the css plugin.

  1. UTF-8 - SUCCESS
  2. UTF-8 with BOM - SUCCESS
  3. UTF-16 LE - SUCCESS
  4. UTF-16 LE with BOM - FAILURE
  5. UTF-16 BE - SUCCESS
  6. UTF-16 BE with BOM - FAILURE
  7. Western (Windows 1252) - SUCCESS
kevinpo
  • 1,853
  • 19
  • 20
0

May be is the file encoding is :UTF-8 encoding with BOM, You should change the file to UTF-8 encoding without BOM

#coding=utf-8
'''
#  prerequisite: python2.7
#  usage:  
#             python utf8-convert.py -h 
#             python utf8-convert.py -f file_path_you_want_to_convert
#  reference links:
#
#  http://stackoverflow.com/questions/8898294/convert-utf-8-with-bom-to-utf-8-with-no-bom-in-python
#  http://stackoverflow.com/questions/3207219/how-to-list-all-files-of-a-directory-in-python
'''

import os
import codecs
import chardet
from optparse import OptionParser


def utf8_converter(file_path, universal_endline=True):
    '''
    Convert any type of file to UTF-8 without BOM
    and using universal endline by default.

    Parameters
    ----------
    file_path : string, file path.
    universal_endline : boolean (True),
                        by default convert endlines to universal format.
    '''

    # Fix file path
    file_path = os.path.realpath(os.path.expanduser(file_path))

    if not os.path.isfile(file_path):
        print '[WARN] filepath is not a file: ' + file_path

    # Read from file
    file_open = open(file_path)
    raw = file_open.read()
    file_open.close()

    file_encoding = str(chardet.detect(raw)['encoding'])
    if raw.startswith(codecs.BOM_UTF8):
        print '[INFO] convert  :encoding('+file_encoding+ ")  " + file_path
    else:
        print '[INFO] skipped  :encoding('+file_encoding+")  " + file_path
        return 0

    # Decode
    raw = raw.decode(chardet.detect(raw)['encoding'])
    # Remove windows end line
    if universal_endline:
        raw = raw.replace('\r\n', '\n')
    # Encode to UTF-8
    raw = raw.encode('utf8')
    # Remove BOM
    if raw.startswith(codecs.BOM_UTF8):
        raw = raw.replace(codecs.BOM_UTF8, '', 1)

    while raw.startswith(codecs.BOM_UTF8):
        raw = raw.replace(codecs.BOM_UTF8, '', 1)

    # Write to file
    file_open = open(file_path, 'w')
    file_open.write(raw)
    file_open.close()
    return 0

if __name__ == "__main__":
    PARSER = OptionParser()
    PARSER.add_option("-f", "--file", action="store", type="string", \
                                      dest="filename", help="file you want to convert")
    OPTIONS, ARGS = PARSER.parse_args()

    if OPTIONS.filename:
        utf8_converter(OPTIONS.filename)
rhinoceros.xn
  • 803
  • 9
  • 12
  • Yes, either the BOM is the problem, or it also doesn't seem to like having a comment as the last thing in the file. – Byson Aug 09 '16 at 15:08