Scan on java with feature preview

I created a maven application running on java 13. In my code, I use some feature preview like switch or multi-line string.

So I use in my pom.xml:

                        <plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<release>${java.version}</release>
					<compilerArgs>--enable-preview</compilerArgs>
					<source>13</source>
					<target>13</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<argLine>@{argLine} --enable-preview</argLine>
				</configuration>
			</plugin>

Last december, I was able to run sonar without any issue.

mvn package
mvn sonar:sonar ....

Since january, I got this error:

[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 13
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=11ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=2ms
[INFO] Java Main Files AST scan
[INFO] 159 source files to be analyzed
[INFO] 159/159 source files have been analyzed
[INFO] Java Main Files AST scan (done) | time=19509ms
[INFO] Java Test Files AST scan
[INFO] 31 source files to be analyzed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:29 min
[INFO] Finished at: 2020-01-20T11:31:34Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project xxxxxx: SonarQube is unable to analyze file : 'src/test/java/com/xxxxxxx/part/OrdersPart.java': Unable to create symbol reference on file src/test/java/com/xxxxxx/part/OrdersPart.java: 57 is not a valid line offset for pointer. File src/test/java/com/xxxxxx/part/OrdersPart.java has 27 character(s) at line 19 -> [Help 1]
[ERROR] 

The OrdersPart.java has this declaration on line 17:

    private static final String CREATE="""
    {
       "address_id": "123",
       "item_id": "13"
    }
    """;

The build before sonar is successful (compile, test ok) so not sure why sonar fail at this point.

Hi,

Welcome to the community!

Did you upgrade to version 6.0 of the Java analyzer in January?

 
Ann

Hello,

I use sonarcloud cloud and there was an upgrade in january.
I use maven plugin 3.7.0.1746.

I guess the java analyser is downloaded from sonarcloud so the latest version?

Hi Gregoire,

Given the following code:

public class Hello {
  private static final String CONSTANT= """
""";
  public static void main(String[] args) {
    System.out.println(CONSTANT);
  }
}

I was able to reproduce the problem using SonarJava 6.0.1.20589 (current version on SonarCloud)

Caused by: java.lang.IllegalArgumentException: Unable to create symbol on file src/main/java/Hello.java
...
Caused by: java.lang.IllegalArgumentException: 21 is not a valid line offset for pointer. File src/main/java/Hello.java has 4 character(s) at line 3
    at org.sonar.api.utils.Preconditions.checkArgument (Preconditions.java:43)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.checkValid (DefaultInputFile.java:339)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.newPointer (DefaultInputFile.java:272)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange (DefaultInputFile.java:287)
    at org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable.newSymbol (DefaultSymbolTable.java:69)
    at org.sonar.java.ast.visitors.SonarSymbolTableVisitor.createSymbol (SonarSymbolTableVisitor.java:124)

And I was not able to reproduce with the bugfix release that will be deployed soon: SonarJava 6.0.2.20657

It was a piece of good news before I discover that we can also have some problem with the highlighting :man_facepalming:, I created this ticket : SONARJAVA-3285

Thanks for the feedback!

2 Likes