Prevents Q UriError : Validate file URI and fallback to Path.toUri() for WSL #5960
+30
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Description
Summary
Fix repeated
UriError
when Amazon Q starts with a WSL-backed workspace. We now validate the constructedfile:
URI and fallback to JDK’sPath.toUri()
if the URI violates Rule (no authority while the path begins with//
, maybe RFC 3986). This keeps legacy behavior where it’s safe, and prevents Q from rejecting the workspace folder URI.Related issues
Root cause
During
InitializeParams
creation,workspaceFolders
receives URIs derived fromVirtualFile
.Internally we were manually constructing file URIs like:
On WSL paths this can become:
This has no authority and a path that starts with
//
, which violates RFC 3986. Amazon Q rejects it with:Older versions reportedly worked because we used a fn in Nio:
[#5462](https://github.com/aws/aws-toolkit-jetbrains/pull/5462/files), when we switched away from the JDK-generated URI toward manual assembly.
What changed
After we build the manual
file:
URI, we inspect the resulting URI:scheme == "file"
andauthority
is empty andpath
starts with//
, it’s considered non-compliant → fallback.Fallback uses JDK normalization:
jar:
andjrt:
handling unchanged.Why fallback (and not just always
Path.toUri()
)?I personally think standardizing on
file.toPath().toAbsolutePath().normalize().toUri()
(or another well-defined canonicalization strategy) would be simpler and sufficient. However, to maintain backward compatibility, address this specific case, and respect any implicit intent behind the current manual construction, I implemented a conservative fallback: we keep the existing construction and only fall back to the JDK-generated URI when the constructed value would violate ruleTests
2025-08-09.015755.mp4
Manually verified with the plugin:
add unit test
Checklist
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.