# Sonar-scanner java.nio.file.InvalidPathException on scanning C++ sources

**URL:** <https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439>\
**Category:** SonarQube Server / Community Build\
**Tags:** cfamily, sonarqube, scanner\
**Created:** [August 8, 2022, 9:12am UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439 "2022-08-08T09:12:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![0x000N3X4N](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/0x000n3x4n/32/35921_2.png) [@0x000N3X4N](https://community.sonarsource.com/u/0x000N3X4N)\
**Post date:** [August 8, 2022, 9:12am UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/1 "2022-08-08T09:12:17Z")

</div>

Hi,  
I got an error on running my sonar-scanner sources:

```auto
java.nio.file.InvalidPathException: Trailing char < > at index 75: E:\BuildAgent\work\c76803df29afe460\KE\sources\\\Common\KEService_defines.h

```

and I see that in build log trailing space in the of a file, but it is missing in the filename.  
The error is reproduced on sonar-scanner v4.6.2.2472 and v4.7.0.2747.  
Can someone help?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [August 8, 2022, 9:51am UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/2 "2022-08-08T09:51:22Z")

</div>

What version of SonarQube are you using?

---

<div class="post-metadata">

**Author:** ![0x000N3X4N](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/0x000n3x4n/32/35921_2.png) [@0x000N3X4N](https://community.sonarsource.com/u/0x000N3X4N)\
**Post date:** [August 8, 2022, 9:54am UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/3 "2022-08-08T09:54:37Z")

</div>

- Enterprise Edition
- Version 9.5 (build 56709)

---

<div class="post-metadata">

**Author:** ![0x000N3X4N](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/0x000n3x4n/32/35921_2.png) [@0x000N3X4N](https://community.sonarsource.com/u/0x000N3X4N)\
**Post date:** [August 8, 2022, 11:30am UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/4 "2022-08-08T11:30:00Z")

</div>

> [14:03:24] : [Step 6/7] 14:03:24.764 DEBUG: ‘KE\sources\Common\KEService\_defines.h’ indexed with language ‘cpp’

> [14:03:42] : [Step 6/7] 14:03:42.522 DEBUG: ‘KE/sources/Common/KEService\_defines.h’ generated metadata with charset ‘UTF-8’

In build log I see that path with correct filename

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [August 8, 2022, 1:30pm UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/5 "2022-08-08T13:30:07Z")

</div>

Take a look at this thread – it may not be the file names on the filesystem that is the issue

> [@Build-wrapper-dump.json does not match analyzer 6.20.4.45706 version](https://community.sonarsource.com/t/build-wrapper-dump-json-does-not-match-analyzer-6-20-4-45706-version/62245/7):
>
> Nope, the actual file names are fine wink The resolving of the includes in c++ causes this issue. Something like this #include "detailtextdlg.h " Will be resolved to a path with trailing whitespaces, which causes the error in WindowsPathParser. The Issue is solved by executing regex search and replace of all include statements that contained a trailing space, for example, #include "detailtextdlg.h " to #include "detailtextdlg.h" i.e: our builds are green again wink

---

<div class="post-metadata">

**Author:** ![0x000N3X4N](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/0x000n3x4n/32/35921_2.png) [@0x000N3X4N](https://community.sonarsource.com/u/0x000N3X4N)\
**Post date:** [August 8, 2022, 6:26pm UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/6 "2022-08-08T18:26:08Z")

</div>

Thank you for help!  
The root cause was really in the whitespace in #include this file, we found it and verify fix and now build status is green.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [August 11, 2022, 11:07am UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/9 "2022-08-11T11:07:37Z")

</div>

Thanks for the follow-up! I can also let you know that in the next release of SonarQube, [we’ll make sure this no longer fails the analysis](https://sonarsource.atlassian.net/browse/CPP-1952).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [August 18, 2022, 11:49am UTC](https://community.sonarsource.com/t/sonar-scanner-java-nio-file-invalidpathexception-on-scanning-c-sources/69439/11 "2022-08-18T11:49:00Z")

</div>

Closed on August 18, 2022, 11:49am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
