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

Safely convert URI to File #19

Merged
merged 2 commits into from
Nov 21, 2013
Merged

Conversation

olivierdagenais
Copy link
Member

Addressing @jglick's comment on f4e33a2 regarding the unsafe conversion of URI to File.

@ghost ghost assigned jglick Nov 19, 2013
@cloudbees-pull-request-builder

plugins » tfs-plugin #24 SUCCESS
This pull request looks good

@@ -76,8 +76,7 @@ static synchronized void ensureNativeLibrariesConfigured() {
// TODO: consider logging this situation if it ever happens
return;
}
final String stringPathToJar = locationUri.getPath();
final File pathToJar = new File(stringPathToJar);
final File pathToJar = new File(locationUri);
Copy link
Member

Choose a reason for hiding this comment

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

Just beware that there is no documented standard format for CodeSource.location. URLClassLoader actually accepts two formats: file:…/code.jar and jar:file:…/code.jar!/. The second one is more logical—code sources ought to be directory URLs to which you can append resource URIs, creating a URL such as jar:file:…/code.jar!/pkg/Some.class. But both forms are found “in the field”, so you should explicitly check for the one using the jar URL protocol and strip off the jar: prefix and !/ suffix before trying to call File.<init>(URI) (which will throw an IllegalArgumentException if given the jar-protocol form), though currently Jenkins uses AntClassLoader whose defineClassFromData uses the file-protocol form, or PluginFirstClassLoader whose addPathFiles does the same. See this code for example.

@cloudbees-pull-request-builder

plugins » tfs-plugin #25 SUCCESS
This pull request looks good

@jenkinsadmin
Copy link
Member

Thank you for a pull request! Please check this document for how the Jenkins project handles pull requests

@olivierdagenais
Copy link
Member Author

@jglick, unless you have any more comments/objections, I will merge this in the afternoon (eastern time) today.

@jglick
Copy link
Member

jglick commented Nov 21, 2013

Looks good to me.

olivierdagenais added a commit that referenced this pull request Nov 21, 2013
@olivierdagenais olivierdagenais merged commit 84b4346 into master Nov 21, 2013
@olivierdagenais olivierdagenais deleted the fixUrlUriPathConversions branch June 19, 2015 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants