Skip to content

Commit 7bd54f1

Browse files
committed
use FilenameUtils.getName because this works on Windows and Linux also if report is generated on the one and consumed on the other
1 parent 6d6b60c commit 7bd54f1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cxx-squid/src/main/java/org/sonar/cxx/utils/CxxReportLocation.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
package org.sonar.cxx.utils;
2121

22-
import java.nio.file.Paths;
2322
import java.util.Objects;
2423
import javax.annotation.Nullable;
24+
import org.apache.commons.io.FilenameUtils;
2525
import org.sonar.api.utils.PathUtils;
2626

2727
/**
@@ -42,10 +42,13 @@ public CxxReportLocation(@Nullable String file, @Nullable String line, @Nullable
4242
// FilenameUtils.normalize internally, relative paths starting with a double dot will cause that path segment
4343
// and the one before to be removed. If the double dot has no parent path segment to work with, null is returned.
4444
// null would mean 'project issue' which is wrong in this context. To avoid this we extract the filename to
45-
// generate at least a meningful error message.
45+
// generate at least a meningful error message (#2747).
4646
var normalized = PathUtils.sanitize(file);
4747
if (normalized == null && (file != null && !file.isBlank())) {
48-
normalized = Paths.get(file).getFileName().toString();
48+
49+
// use FilenameUtils.getName because this works on Windows and Linux also if
50+
// report is generated on the one and consumed on the other
51+
normalized = FilenameUtils.getName(file);
4952
}
5053

5154
this.file = normalized;

0 commit comments

Comments
 (0)