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

Calvin Cheung ccheung at openjdk.org
Tue Sep 10 20:54:07 UTC 2024


On Tue, 10 Sep 2024 07:24:08 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> src/hotspot/share/classfile/classLoaderExt.cpp line 221:
>> 
>>> 219:       dir_tail = strrchr(dir_name, '/');
>>> 220:     }
>>> 221: #endif
>> 
>> The value of the Class-Path attribute is a sequence of relative URLs, not file paths, so I wouldn't expect to see any usage of os::file_separator() here, even on Unix systems. Some further work may be needed here to align with how the Class-Path attribute is treated by the application class loader.
>
> Given these are required to be relative URLs [1] and given the path component of a URL only uses '/' as a separator [2], then it would seem the use of `os::file_separator` is wrong and it should just be hardcoded to '/' - and further it means the current code has never been correct on Windows. ??
> 
> [1] https://docs.oracle.com/en/java/javase/21/docs/specs/jar/jar.html#class-path-attribute
> [2] https://en.wikipedia.org/wiki/URL

Consider `java -cp dir1/A.jar` ... where the manifiest of A.jar contains:
`Class-Path: a.jar`
The `dir_name` in the above corresponds to `dir1/A.jar`. The `strrchr` is trying to locate the separator between the directory and jar name. Later in the same function, it will combine the directory name (in this case `dir1`) with the names from each of the entry from the attribute and create a class path entry. In the example, it will create a class path entry of `dir1/a.jar`.
Before the patch, on Windows, it only works with '\' (the default file separator). e.g.` java -cp dir1\A.jar` ... .

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

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


More information about the hotspot-runtime-dev mailing list