-
Notifications
You must be signed in to change notification settings - Fork 137
fix(context): читать модули по UNC через Path.of #4482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -294,6 +294,22 @@ void testUntitledSchemaFromVSC() { | |
| assertThat(documentContext.getFileType()).isEqualTo(FileType.BSL); | ||
| } | ||
|
|
||
| @Test | ||
| void rebuildFromFileSystemDoesNotThrowOnUriWithAuthority() { | ||
| // given: LSP-клиент на UNC отдаёт file://host/share/... — у URI есть authority. | ||
| // new File(uri) бросает IllegalArgumentException и рвёт populateContext. | ||
| var uri = URI.create("file://192.168.113.131/share/does-not-exist.bsl"); | ||
| var documentContext = TestUtils.getDocumentContext( | ||
| uri, | ||
| "Процедура Тест() КонецПроцедуры", | ||
| TestUtils.getRegisteredServerContext() | ||
| ); | ||
|
|
||
| // when-then: нет файла → IOException; на Unix Path.of(file://host/...) → IAE. | ||
| // Оба логируются, populate не рвётся. | ||
| assertThatCode(documentContext::rebuildFromFileSystem).doesNotThrowAnyException(); | ||
| } | ||
|
Comment on lines
+297
to
+311
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- candidate files ---'
git ls-files | rg '(^|/)(DocumentContextTest\.java|DocumentContext\.java|TestUtils\.java)$'
printf '%s\n' '--- relevant symbols ---'
rg -n -t java 'rebuildFromFileSystem|new File\(|Path\.of\(|Paths\.get\(|URI' \
src/test/java src/main/java 2>/dev/null | head -240
printf '%s\n' '--- targeted test ---'
test_file="$(git ls-files | rg '(^|/)DocumentContextTest\.java$' | head -1)"
if [ -n "$test_file" ]; then
cat -n "$test_file" | sed -n '270,325p'
fi
printf '%s\n' '--- implementation outline ---'
impl_file="$(git ls-files | rg '(^|/)DocumentContext\.java$' | head -1)"
if [ -n "$impl_file" ]; then
ast-grep outline "$impl_file" || true
rg -n -A35 -B12 'rebuildFromFileSystem|new File\(|readString|populateContext' "$impl_file" || true
fiRepository: 1c-syntax/bsl-language-server Length of output: 47357 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- Absolute utility files ---'
git ls-files | rg '(^|/)Absolute[^/]*\.(java|kt|groovy)$|(^|/)absolute[^/]*\.(java|kt|groovy)$'
printf '%s\n' '--- Absolute references and declarations ---'
rg -n -t java 'class Absolute|interface Absolute|record Absolute|Absolute\.path|Absolute\.uri|static .*path\(.*URI|Path path\(.*URI' \
src/main/java src/test/java 2>/dev/null | head -240
printf '%s\n' '--- relevant utility source ---'
absolute_file="$(git ls-files | rg '(^|/)Absolute[^/]*\.java$' | head -1)"
if [ -n "$absolute_file" ]; then
wc -l "$absolute_file"
ast-grep outline "$absolute_file" || true
cat -n "$absolute_file" | sed -n '1,260p'
fi
printf '%s\n' '--- relevant tests ---'
rg -n -A25 -B10 -t java 'Absolute\.path|Absolute\.uri|authority|UNC|unc' src/test/java src/main/java 2>/dev/null | head -320Repository: 1c-syntax/bsl-language-server Length of output: 198 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- imports and references ---'
rg -n -t java 'import .*Absolute|Absolute\.|class Absolute|interface Absolute|record Absolute' . 2>/dev/null | head -300 || true
printf '%s\n' '--- DocumentContext imports and surrounding implementation ---'
sed -n '1,125p' src/main/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContext.java
cat -n src/main/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContext.java | sed -n '380,435p'
printf '%s\n' '--- build declarations mentioning the defining library ---'
rg -n 'absolute|Absolute|commons|path' pom.xml build.gradle* settings.gradle* gradle.properties .mvn 2>/dev/null | head -240 || true
printf '%s\n' '--- repository file names containing absolute ---'
git ls-files | rg -i 'absolute|pathutil|uriutil|filesystem' | head -200 || trueRepository: 1c-syntax/bsl-language-server Length of output: 50385 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- dependency declaration ---'
rg -n -A8 -B8 '1c-syntax|utils|absolute' pom.xml build.gradle* settings.gradle* gradle.properties .mvn 2>/dev/null | head -180 || true
printf '%s\n' '--- TestUtils relevant methods ---'
cat -n src/test/java/com/github/_1c_syntax/bsl/languageserver/util/TestUtils.java | sed -n '35,115p'
cat -n src/test/java/com/github/_1c_syntax/bsl/languageserver/util/TestUtils.java | sed -n '165,205p'
printf '%s\n' '--- DocumentContext construction and rebuild calls ---'
rg -n -A28 -B18 -t java 'DocumentContext\(|rebuildFromFileSystem\(|rebuild\(' \
src/main/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContext.java \
src/test/java/com/github/_1c_syntax/bsl/languageserver/util/TestUtils.java \
src/test/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContextTest.java | head -320Repository: 1c-syntax/bsl-language-server Length of output: 50385 🌐 Web query:
💡 Result: In the 1c-syntax project ecosystem, com.github._1c_syntax.utils.Absolute is a utility class provided by the 1c-syntax/utils library [1][2]. It is designed to handle the normalization and conversion of URIs to filesystem paths, ensuring consistent path handling across different environments [3][4]. This utility is frequently used within the bsl-language-server to resolve and normalize file locations, preventing errors associated with raw URI-to-path conversions (such as those involving network authorities or inconsistent URI formatting) [3][4]. For example, developers use methods like Absolute.uri and Absolute.path as a project-wide convention to guarantee that paths derived from various sources remain consistent and reliable [3]. Using this utility helps avoid common issues like java.lang.IllegalArgumentException when processing URIs with authority components [4]. Citations:
🏁 Script executed: #!/bin/bash
set -eu
api='https://api.github.com/repos/1c-syntax/utils/git/trees/master?recursive=1'
tree="$(curl -fsSL "$api")"
printf '%s\n' '--- Absolute source paths ---'
printf '%s' "$tree" | jq -r '.tree[]?.path' | rg '(^|/)Absolute\.java$|(^|/)absolute' || true
printf '%s\n' '--- tags containing 0.10 ---'
curl -fsSL 'https://api.github.com/repos/1c-syntax/utils/tags?per_page=100' |
jq -r '.[].name' | rg '0\.10|0\.9|0\.8' || true
printf '%s\n' '--- dependency metadata ---'
curl -fsSL 'https://repo1.maven.org/maven2/io/github/1c-syntax/utils/0.10.1/utils-0.10.1.pom' |
rg -n 'version|artifactId|groupId' | head -60 || trueRepository: 1c-syntax/bsl-language-server Length of output: 1083 🏁 Script executed: #!/bin/bash
set -eu
url='https://raw.githubusercontent.com/1c-syntax/utils/v0.10.1/src/main/java/com/github/_1c_syntax/utils/Absolute.java'
curl -fsSL "$url" | nl -ba | sed -n '1,280p'Repository: 1c-syntax/bsl-language-server Length of output: 276 🏁 Script executed: #!/bin/bash
set -eu
url='https://raw.githubusercontent.com/1c-syntax/utils/v0.10.1/src/main/java/com/github/_1c_syntax/utils/Absolute.java'
curl -fsSL "$url" | cat -n | sed -n '1,280p'Repository: 1c-syntax/bsl-language-server Length of output: 6776 🏁 Script executed: #!/bin/bash
set -eu
if command -v java >/dev/null 2>&1 && command -v jshell >/dev/null 2>&1; then
java -version 2>&1 | head -3
jshell <<'JS'
import java.net.URI;
import java.nio.file.Path;
var uri = URI.create("file://192.168.113.131/share/does-not-exist.bsl");
System.out.println("scheme=" + uri.getScheme());
System.out.println("authority=" + uri.getAuthority());
try {
System.out.println(Path.of(uri));
} catch (Throwable t) {
System.out.println(t.getClass().getName() + ": " + t.getMessage());
}
JS
else
printf '%s\n' 'java/jshell unavailable'
fiRepository: 1c-syntax/bsl-language-server Length of output: 191 🏁 Script executed: #!/bin/bash
set -eu
for file in \
src/java.base/share/classes/java/nio/file/Paths.java \
src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java \
src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java
do
url="https://raw.githubusercontent.com/openjdk/jdk21u/master/$file"
printf '%s\n' "--- $file ---"
curl -fsSL "$url" | rg -n -A14 -B6 'getPath\(URI|authority component|uri\.getAuthority' || true
doneRepository: 1c-syntax/bsl-language-server Length of output: 1800 🏁 Script executed: #!/bin/bash
set -eu
for file in \
src/java.base/unix/classes/sun/nio/fs/UnixUriUtils.java \
src/java.base/windows/classes/sun/nio/fs/WindowsUriSupport.java
do
url="https://raw.githubusercontent.com/openjdk/jdk21u/master/$file"
printf '%s\n' "--- $file ---"
curl -fsSL "$url" | rg -n -A45 -B8 'fromUri|authority|URI has' | head -180
doneRepository: 1c-syntax/bsl-language-server Length of output: 6816 Make the URI regression test platform-independent. On Windows, 🤖 Prompt for AI Agents |
||
|
|
||
| @SneakyThrows | ||
| public DocumentContext getDocumentContext() { | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 31919
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 412
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 50386
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 50386
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 15718
🌐 Web query:
Find the source or API documentation for com.github._1c_syntax.utils.Absolute.path(URI), including how it handles file URIs with a non-empty authority component.💡 Result:
The class com.github._1c_syntax.utils.Absolute is a utility component within the 1c-syntax/utils library [1]. Its primary purpose is to normalize file paths and URIs into a canonical, absolute form to ensure consistent identity for files regardless of how they are represented [2]. Regarding the handling of file URIs with a non-empty authority component (such as network shares): 1. Historical Handling: Early versions of the Absolute.path(URI) method utilized the java.io.File constructor, which frequently threw an IllegalArgumentException when encountering file URIs with an authority component (e.g., file://server/path/file.ext), as java.io.File does not natively support authority components [3]. 2. Resolution: To address this limitation, the 1c-syntax project implemented specific fixes (such as those documented in issue
#934and subsequent pull requests) to explicitly handle URIs containing server names or network authorities [3]. The utility is intended to be used as the standard way to normalize URI-to-filesystem conversions across the project's ecosystem [4][2]. Developers are advised to use Absolute.path(URI) and Absolute.uri(String/File) instead of direct standard library conversions (like URI.create or new File(URI)) to avoid edge-case failures and maintain path consistency [4]. Documentation for the latest version can be found on Javadoc.io [5].Citations:
🌐 Web query:
Java 21 Path.of(URI) Unix provider behavior for file URI with non-empty authority component file://host/share/path💡 Result:
In Java 21, the behavior of Path.of(URI) regarding the authority component (e.g., file://host/share/path) is platform-specific and implementation-dependent for the default file system provider [1]. While the Java documentation specifies that the "file" scheme requires a non-empty path component and undefined query and fragment components, it explicitly notes that the presence of an authority component is implementation-dependent [1]. On Unix-based systems, the default file system provider generally does not support or utilize the authority component in the same way it might for Windows UNC paths [1]. In practice, if you pass a URI with a non-empty authority component to Path.of(URI) on a system where the default provider expects a simple path (or does not recognize the authority), it may lead to an IllegalArgumentException or unexpected path resolution, depending on the specific JDK implementation and the OS [1][2]. Unlike the java.io.File(URI) constructor, which has historically been strict and explicitly throws an IllegalArgumentException if an authority component is present [3], Path.of(URI) defers the handling of the URI to the installed file system providers [1]. Because there is no guarantee that a URI with an authority component can be correctly converted to a Path across all platforms, developers are advised to use the appropriate conversion methods provided by the Path API (e.g., Path.toUri) to maintain compatibility and round-trip integrity [1][4]. If you are working with network shares or non-local paths, you should ensure you are using a file system provider that explicitly supports those URI formats, rather than relying on the default "file" provider [1].
Citations:
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 12254
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 5619
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 8787
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 2925
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 8024
Handle authority-bearing
fileURIs before converting them toPath.On Unix,
Path.of(uri)throwsIllegalArgumentException: URI has an authority componentforfile://host/share/....Absolute.path(uri)inutils:0.10.1also delegates toPath.of(uri(uri))and preserves the authority, so restoring it does not fix either call site. Use an authority-aware conversion or handle unsupported authorities explicitly.📍 Affects 2 files
src/main/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContext.java#L423-L424(this comment)src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/GitBlameComputer.java#L65-L65🤖 Prompt for AI Agents