Upgrade sonar-plugin-api and fix IndexedFile issue

Description

In the project root pom.xml, the following dependencies need to be updated to the following versions:

A change that happened in org.sonar.api.batch.fs.internal.DefaultIndexedFile in sonar-plugin-api-impl:10.4.1.88267 makes the tests fail however.

Problem description:

In API version 9.9, DefaultIndexedFile:

was replaced in version 10.4 by:


This makes now several tests fail where PathUtils.checkSanitize(projectRelativePath); previously returned null, but checkSanitize(projectRelativePath); throws an exception.

This happens due to the following constructor invocation in java-frontend/src/test/java/org/sonar/java/TestUtils.java and java-symbolic-execution/src/test/java/org/sonar/java/se/utils/SETestUtils.java:

The problem here is that file is a file generated in the temp folder, which is not under the project folder moduleKey. The TestInputFileBuilder creates a relative path from the module folder to the temp file, which is then something like ../../../../temp/foo/foo.tmp. Sanitizing this relative path returns null, which also happened before but did not throw an exception.

 

An obvious solution which we tried is instead of inferring the moduleBaseDir from the project key, use this constructor and give it a moduleBaseDir explicitly. So we changed:

to:

in both classes.

This, however, made org.sonar.java.StrutsTest and org.sonar.java.DefaultIndexedFile fail. Because classes are now visited somewhat differently and in a different order, their expected metrics numbers changed (e.g., metrics.get("classes") ... isEqualTo(146) -> metrics.get("classes") ... isEqualTo(145))

The changes were therefore rolled back and a better solution would be to create an own implementation of IndexedFile with the old (or a simplified) behavior.

Activity

Done
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Components

Fix versions

Priority

Sentry

Created March 27, 2024 at 12:13 PM
Updated October 16, 2024 at 2:06 PM
Resolved April 4, 2024 at 9:00 AM