-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8338626: ClassLoaderExt::process_jar_manifest() should allow / separator on Windows #20924
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
8338626: ClassLoaderExt::process_jar_manifest() should allow / separator on Windows #20924
Conversation
👋 Welcome back ccheung! A progress list of the required criteria for merging this PR into |
@calvinccheung This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 223 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@calvinccheung The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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.
LGTM! Just one note of the test
@@ -82,6 +83,40 @@ static void testNormalOps() throws Exception { | |||
output.shouldMatch("checking shared classpath entry: .*cpattr2.jar"); | |||
output.shouldMatch("checking shared classpath entry: .*cpattr3.jar"); | |||
}); | |||
|
|||
// Test handling of forward slash ('/') file separator for Class-Path attribute on Windows. | |||
if (Platform.isWindows()) { |
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.
Does the new test work for other platforms as well? If so, I think we should remove this check.
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.
It does. Since other platforms have '/' as the file separator, running it again would be wasting of time.
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.
That makes sense.
if (dir_tail == nullptr) { | ||
dir_tail = strrchr(dir_name, '/'); | ||
} | ||
#endif |
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.
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.
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.
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
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.
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
... .
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.
Also, the modified function is only called during CDS dump time for setting up the shared class paths for the app class loader.
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.
To me it sounds like the logic should be always using /
to locate and then use file_seperator to rewrite to a classpath filesystem entry.
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.
Just to repeat what I said previously, the value of Class-Path attribute is a sequence of relative URLs. The code in ClassLoaderExt::process_jar_manifest will work for some cases but in general, the appending used in this function can't be worked to combine a file path and URL path.
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.
Alan, could you show us some cases where ClassLoaderExt::process_jar_manifest() will fail. IIUC, the failures won't be Windows-specific (i.e., orthogonal to the \ vs / issues in this bug) but rather will happen on all platforms.
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.
Can you try examples like file:lib.jar
, file:/d/lib.jar
, /d/lib.jar
for starters. Once you bring Windows file paths into the picture then it's a world of hurt. There is big other topic around escaping where Class-Path is completely broken and we haven't figure out how to fix these issues in a compatibility way.
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.
Sorry, I didn't notice last few comments until after pushing the fix. I think if there's any other shortcoming of the function in question, it should be addressed via different bug/RFE.
After a casual search for Class-Path attribute, I found: https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#classpath
It says the following:
Currently, the URLs must be relative to the code base of the JAR file for security reasons. Thus, remote optional packages will originate from the same code base as the application.
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.
It says the following:
Currently, the URLs must be relative to the code base of the JAR file for security reasons. Thus, remote optional packages will originate from the same code base as the application.
That's right but there are a lot of issues here that date back to JDK 1.2 when the feature was added. We also have a long standing issue that tooling and plugins in the eco system are putting all manner of values into the attribute value, which has constrained us from fixing some of the fundamental issues. The summary is that the resolving the value against the base URL in the code here isn't the same as that done by the application class loader.
#ifdef _WINDOWS | ||
// On Windows, we also support forward slash as the file separator for Class-Path: attribute. | ||
if (dir_tail == nullptr) { | ||
dir_tail = strrchr(dir_name, '/'); |
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.
There's still a bug in the current patch. If the input is
java -cp a\b/c.jar
The current patch gets "a" as the directory name, but it should get "a\b" instead.
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.
I've pushed an updated fix to address this above. Also added a test.
@@ -213,6 +213,15 @@ void ClassLoaderExt::process_jar_manifest(JavaThread* current, ClassPathEntry* e | |||
char sep = os::file_separator()[0]; | |||
const char* dir_name = entry->name(); | |||
const char* dir_tail = strrchr(dir_name, sep); | |||
#ifdef _WINDOWS | |||
// On Windows, we also support forward slash as the file separator when locating entries in the Class-Path: attribute. |
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.
// On Windows, we also support forward slash as the file separator when locating entries in the Class-Path: attribute. | |
// On Windows, we also support forward slash as the file separator when locating entries in the classpath entry. |
The forward slash is not being used in relation to any Class-path attribute here.
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.
Updated the comment.
Also updated the test so it can be run more reliably.
@@ -82,6 +83,75 @@ static void testNormalOps() throws Exception { | |||
output.shouldMatch("checking shared classpath entry: .*cpattr2.jar"); | |||
output.shouldMatch("checking shared classpath entry: .*cpattr3.jar"); | |||
}); | |||
|
|||
// Test handling of forward slash ('/') file separator for Class-Path attribute on Windows. |
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.
Again this comment is wrong/misleading - the / is in the classpath entry
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.
Updated the comment.
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.
Okay. Thanks
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.
LGTM
Thanks @matias9927, @iklam, @dholmes-ora, @AlanBateman for the review. /integrate |
Going to push as commit 89ca89c.
Your commit was automatically rebased without conflicts. |
@calvinccheung Pushed as commit 89ca89c. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
On Windows, we can use '/' as the file separator in the classpath but not in the
Class-Path:
attribute.This patch is to enable the use of '/' as the file separator in the
Class-Path:
attribute on Windows.Passed tiers 1 - 3 testing.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20924/head:pull/20924
$ git checkout pull/20924
Update a local copy of the PR:
$ git checkout pull/20924
$ git pull https://git.openjdk.org/jdk.git pull/20924/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20924
View PR using the GUI difftool:
$ git pr show -t 20924
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20924.diff
Webrev
Link to Webrev Comment