Skip to content
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

8352858: Make java.net.JarURLConnection fields final #24218

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/java.base/share/classes/java/net/JarURLConnection.java
Original file line number Diff line number Diff line change
@@ -160,32 +160,32 @@ protected JarURLConnection(URL url) throws MalformedURLException {

// Extract JAR file URL and entry name components from the URL
String spec = url.getFile();
int separator = spec.indexOf("!/");
int separatorIndex = spec.indexOf("!/");

// REMIND: we don't handle nested JAR URLs
Copy link
Contributor Author

@eirbjo eirbjo Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that this comment seems misplaced and is confusing.

The check just asserts that the URL contains the separator. I don't see how this is related to nesting at all. If the URL was nested, we would have more than one separator, right?

If we agree this comment is misplaced, perhaps we should just remove it?

Or perhaps the REMIND here is a type of TODO?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is just a reminder that there should just be one single "!/" because nested "!/" in URL are not supported.

Copy link
Contributor Author

@eirbjo eirbjo Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, however mysterious it seems to carry some value. Let's keep it around.

Thanks for your reviews!

if (separator == -1) {
if (separatorIndex == -1) {
throw new MalformedURLException("no !/ found in url spec:" + spec);
}

jarFileURL = parseJarFileURL(spec, separator, url);
entryName = parseEntryName(spec, separator);
jarFileURL = parseJarFileURL(spec, separatorIndex, url);
entryName = parseEntryName(spec, separatorIndex);
}

/**
* Parse the URL of the JAR file backing this JarURLConnection,
* appending any #runtime fragment as neccessary
*
* @param spec the URL spec of this connection
* @param separator the index of the '!/' separator
* @param separatorIndex the index of the '!/' separator
* @param connectionURL the URL passed to the constructor
* @return a URL to the JAR file this connection reads from
*
* @throws MalformedURLException if a malformed URL is found
*/
@SuppressWarnings("deprecation")
private static URL parseJarFileURL(String spec, int separator, URL connectionURL) throws MalformedURLException {
private static URL parseJarFileURL(String spec, int separatorIndex, URL connectionURL) throws MalformedURLException {

URL url = new URL(spec.substring(0, separator));
URL url = new URL(spec.substring(0, separatorIndex));
/*
* The url passed to the constructor may have had a runtime fragment appended, so
* we need to add a runtime fragment to the jarFileURL to enable
@@ -201,16 +201,16 @@ private static URL parseJarFileURL(String spec, int separator, URL connectionURL
* Parse the entry name (if any) of this JarURLConnection
*
* @param spec the URL spec of this connection
* @param separator the index of the '!/' separator
* @param separatorIndex the index of the '!/' separator
* @return the decoded entry name, or null if this URL has no entry name
*/
private static String parseEntryName(String spec, int separator) {
private static String parseEntryName(String spec, int separatorIndex) {
// If the URL ends with the '!/' separator, entryName is null
int nameIdx = separator + 2;
if (nameIdx == spec.length()) {
int nameIndex = separatorIndex + 2;
if (nameIndex == spec.length()) {
return null;
} else {
String encodedName = spec.substring(nameIdx, spec.length());
String encodedName = spec.substring(nameIndex, spec.length());
return ParseUtil.decode(encodedName);
}
}