RFR: 8338626: CDS handling of JAR Class-Path attribute should allow / separator on Windows

Ioi Lam iklam at openjdk.org
Wed Sep 11 07:41:05 UTC 2024


On Wed, 11 Sep 2024 07:00:15 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> My question still remains: does regular classpath handling allow both forward- and back-slashes on Windows?
>
> Based on Calvin's description, and the definition of the `Class-path` attribute then the code to extract foo.jar should always be using `/` not `os::file_separator`, and then the classpath element should be constructed using `os::file_separator`.

The Windows file API allows both `/` and ``. E.g., `os::open("foo/bar.jar", ...)` and `os::open("foo\\bar.jar", ...)` are equivalent. So in most cases, we just pass the path specified by the user to the OS, without doing any `/` to `` conversion. That's why both `java -cp foo/bar.jar` and `java -cp foo\bar.jar` work on Windows.
 
The bug in this particular case is: CDS needs to construct the path to a JAR file specified in the ClassPath attribute. As describe in the bug report, the test case is:


java -cp foo/bar.jar


and bar.jar contains


Class-Path: lib.jar


CDS needs to construct the string "foo\lib.jar". This is done by

- finding the directory that contains "foo/bar.jar" (which should be "foo")
- appending "\lib.jar" to this directory (which gives us "foo\lib.jar")

The bug is that CDS fails to find the "foo" directory. This is BEFORE any processing of the ClassPath attribute of bar.jar itself.

The fix is -- to be able to find the  directory name, we need to find the longest prefix of the input that ends with either "/" or "".

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20924#discussion_r1753413925


More information about the hotspot-runtime-dev mailing list