On Tue, 19 May 2026 23:48:31 GMT, Ashay Rane <[email protected]> wrote:

> Although the original implementation of `JLI_Open()` borrowed from the
> code in src/hotspot/os/windows/os_windows.cpp, the improvements to
> os_windows.cpp don't seem to have been applied to java_md.c, causing
> some tests to fail when the path to JAR files is longer than `MAXPATH`
> (i.e. 260) characters on Windows (see associated JBS issue 8385024 for
> details).  Since `JLI_Open()` is not just invoked inside tests, this is
> not a test-specific issue, so fixing the test is not the right solution.
> 
> This patch applies the recent changes from os_windows.cpp to java_md.c
> so that `JLI_Open()` can correctly handle longer than `MAXPATH` paths.
> The new code is almost the same as that in `wide_abs_unc_path()` in
> os_windows.cpp, except that the code in java_md.c uses `JLI_MemAlloc()`
> and `JLI_MemFree()` for memory allocation and deallocation.
> 
> Although it would be ideal to have just one implementation between
> HotSpot and the launcher, the dependencies of the two components
> prevents us from having a single implementation.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/java.base/windows/native/libjli/java_md.c line 526:

> 524:         JLI_MemFree(*full_path);
> 525:         *full_path = NULL;
> 526:         return EINVAL;

The value specified to `java -jar` will unlikely have the long path prefix so I 
assume get_full_path will be used and this means 2 x calls to GetFullPathNameW. 
We may have to check if this impacts startup, or maybe only call it when the 
prefix is needed.

src/java.base/windows/native/libjli/java_md.c line 557:

> 555: 
> 556: /* Adapted from HotSpot's wide_abs_unc_path() in os_windows.cpp. */
> 557: static wchar_t* create_unc_path(const char* path, errno_t* err) {

I wonder if we could look for a better name for this as it should be rare for 
this function to create a UNC path, it's really that it adds the long path 
prefix.

src/java.base/windows/native/libjli/java_md.c line 615:

> 613:     fd = _wopen(wpath, flags);
> 614:     if (fd == -1) {
> 615:         errno = GetLastError();

_wopen is documented to set errno so I'm not sure why it uses GetLastError (not 
your issue, it did this previously, only wondering about it as it has moved so 
showing up as diffs).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31209#discussion_r3281400511
PR Review Comment: https://git.openjdk.org/jdk/pull/31209#discussion_r3281467221
PR Review Comment: https://git.openjdk.org/jdk/pull/31209#discussion_r3281452420

Reply via email to