ERROR: Error during SonarQube Scanner execution

3,745 views
Skip to first unread message

Zakaryae Amekkaoui

unread,
Jan 24, 2018, 5:37:01 AM1/24/18
to SonarQube
Hi everyone,

I'm trying to scan a project, but i get this error :
ERROR: Error during SonarQube Scanner execution java.lang.IllegalArgumentException: 26298 is not a valid line for pointer.

I tried to specify the encoding in sonar-project.properties ( sonar.sourceEncoding=UTF-8), but it doesn't work.

I'm using windows8-64.

Thank you,
Have a nice day

Zack.

Scott B.

unread,
Jan 24, 2018, 10:39:55 AM1/24/18
to SonarQube
Hi.

You didn't say what is the SonarQube version, what programming language you're analyzing, what is the plugins and versions installed on your instance... Nobody will help you.

Zakaryae Amekkaoui

unread,
Jan 24, 2018, 11:25:23 AM1/24/18
to SonarQube
Hi Scott,

Thanks for your response, i'm using version 6.7.1 for SonarQube and sonar-scanner-3.0.3.778.
The programming language is NCL.

This is the rest of the error message  :

INFO: 168/168 source files have been analyzed
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 4:21.153s
INFO: Final Memory: 87M/1611M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalArgumentException: 662742 is not a valid line for pointer. File
 sources/AGAS1.EXP has 3974 line(s)
        at org.sonar.api.internal.google.common.base.Preconditions.checkArgument
(Preconditions.java:145)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.checkValid(DefaultIn
putFile.java:309)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.newPointer(DefaultIn
putFile.java:246)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.selectLine(DefaultIn
putFile.java:269)
        at org.sonar.plugins.ncl.NclSquidSensor.saveViolations(NclSquidSensor.ja
va:213)
        at org.sonar.plugins.ncl.NclSquidSensor.save(NclSquidSensor.java:123)
        at org.sonar.plugins.ncl.NclSquidSensor.execute(NclSquidSensor.java:106)

        at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)

        at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecuto
r.java:88)

Scott B.

unread,
Jan 24, 2018, 12:45:23 PM1/24/18
to SonarQube
Oh boy... this is a custom plugin, right? Is your plugin or it's from a third party? Anyway, it seems a bug in the plugin.

In older SonarQube versions, to read the contents of a org.sonar.api.batch.fs.InputFile, the only option was to use the default encoding (defined in the sonar.sourceEncoding property).

Since SonarQube ~6.3, the platform got smarter and started to detect the file encoding automatically. But it has a downside: when you read the file using an encoding diffent than the detected by SonarQube you can hit this "xxxx is not a valid line for pointer" exceptions.

An easier option is to fix the encoding of your source code, to leave all files with the same encoding. Then define sonar.sourceEncoding and you'll be ok.

If you want to fix the plugin, I'm sorry to say: you have a long journey ahead. The only definitive way to fix the plugin is to NOT read the file manually (like "Files.toString(inputFile.file(), charset)") and start to use the InputFile.contents method (avaliable in sonar-plugin-api 6.2).

Just remembering how hard I worked to fix this in a custom plugin gives me headhaches.

Zakaryae Amekkaoui

unread,
Jan 25, 2018, 4:13:44 AM1/25/18
to SonarQube
Yeep it's a custom plugin for a proprietary language.

I tried the first solution but it doen't work, so i've to try the second one.

Thanks very much Scott for your response.

Have a nice day.

Zakaryae Amekkaoui

unread,
Jan 31, 2018, 5:44:17 AM1/31/18
to SonarQube
Hi Scott again,

I tried the second solution, but i stell have the error "java.nio.charset.malformedinputexception input length = 1".

My solution is like : 

@Override
public void visitFile(@Nullable AstNode astNode) {

       String pth = getContext().getFile().toString(); 
       try { 
              Stream<String> lignes = Files.lines(Paths.get(pth));
              lignes.forEach(line -> {

           .....
           });
      }
}

Do you have any idea for this problem ?
Thanks.

Have a nice day.
Zack

Julien HENRY

unread,
Jan 31, 2018, 9:30:40 AM1/31/18
to SonarQube
Hi Zack,

Using Files.lines() without specifying encoding means you are assuming all files are encoded in UTF-8. We have an algorithm to detect encoding in SonarQube, and so the safest way to be sure you are processing the input file with the same encoding as the one detected by SonarQube is to use InputFile::charset() API.

Regards,

Julien

Zakaryae Amekkaoui

unread,
Feb 1, 2018, 5:02:14 AM2/1/18
to SonarQube
Hi Julien,

Thank you for your response, can you please tell me how can i use this API ? i didin't found an example for that.


Regards.
Zack

Julien HENRY

unread,
Feb 1, 2018, 5:07:16 AM2/1/18
to Zakaryae Amekkaoui, SonarQube

Julien Henry | SonarSource

Developer

https://sonarsource.com


--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/__TXqiQaEYo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/b825e649-5e43-429d-bf31-32cc030af526%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Zakaryae Amekkaoui

unread,
Feb 1, 2018, 11:37:23 AM2/1/18
to SonarQube
Hi,

Thanks a lot Julien, in my NCLSuiqSensor i have this code :
  @Override
  public void execute(SensorContext context) {
    FileSystem fileSystem = context.fileSystem();
    FilePredicates predicates = fileSystem.predicates();
    List<SquidAstVisitor<LexerlessGrammar>> visitors = new ArrayList<>(checks.all());
    visitors.add(new FileLinesVisitor(fileLinesContextFactory, fileSystem));
    NclConfiguration configuration = new NclConfiguration(fileSystem.encoding());

    scanner = NclAstScanner.create(configuration, visitors);

    Iterable<java.io.File> files = fileSystem.files(
      predicates.and(
        predicates.hasType(InputFile.Type.MAIN),
        predicates.hasLanguage(Ncl.KEY),
        inputFile -> !inputFile.absolutePath().endsWith("mxml")
      ));
    scanner.scanFiles(ImmutableList.copyOf(files));

    Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class));
    save(context, squidSourceFiles);
  }


So i tried to change the configuration to UTF-8, come thing like that  :
   NclConfiguration configuration = new NclConfiguration(Charset.forName("UTF-8"));

But it doesn't work. Do you have any suggestion ?
Thanks.


Have a nice day.

Regards.
Zack.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

Julien HENRY

unread,
Feb 1, 2018, 11:55:32 AM2/1/18
to Zakaryae Amekkaoui, SonarQube
I'm sorry but I'm not very confident with SSLR/sonar-channel library. You can maybe look at open source SonarSource code analyzers to see how they are managing to pass the InputFile charset to the SourceCode layer.

Julien Henry | SonarSource

Developer

https://sonarsource.com


To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/4691b2cf-0cda-49ec-9e64-b03165100f07%40googlegroups.com.

Zakaryae Amekkaoui

unread,
Feb 1, 2018, 11:56:58 AM2/1/18
to SonarQube
Okey thanks a lot Julien :)

Regards
Zack
Reply all
Reply to author
Forward
0 new messages