Skip to content

Replace deprecated File.toURL() #1847

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void startup(IPath root) {
if (rootURL != null)
return;
try {
rootURL = root.toFile().toURL();
rootURL = root.toFile().toURI().toURL();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is a place we want to fix because, as also mentioned in #35 (comment), the URL produced here potentially reaches client code outside of the Eclipse platform and they might expect it to be wrongly encoded just as it used to be. So fixing this might be a compatibility problem.
I believe that is also the reason that all the FileLocator methods where not yet fixed to return properly encoded URLs, but I don't know the exact discussion about this.
Maybe @tjwatson or @merks know if/when/where this was discussed?

In general please be very careful when fixing the URL conversions. The change looks so simple, but it can cause major compatibility problems in unfortunate cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

} catch (MalformedURLException e) {
// should never happen but if it does, the resource URL cannot be supported.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.update.configurator; singleton:=true
Bundle-Version: 3.5.600.qualifier
Bundle-Version: 3.5.700.qualifier
Bundle-Activator: org.eclipse.update.internal.configurator.ConfigurationActivator
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private PlatformConfiguration(Location platformConfigLocation) throws CoreExcept
// Retrieve install location with respect to given url if possible
try {
if (url != null && url.getProtocol().equals("file") && url.getPath().endsWith("configuration/org.eclipse.update/platform.xml")) {
installLocation = IPath.fromOSString(url.getPath()).removeLastSegments(3).toFile().toURL();
installLocation = IPath.fromOSString(url.getPath()).removeLastSegments(3).toFile().toURI().toURL();
}
} catch (Exception e) {
//
Expand Down Expand Up @@ -853,7 +853,7 @@ private Configuration loadConfig(URL url, URL installLocation) throws Exception
if (workingDir != null && workingDir.exists()) {
File[] backups = workingDir.listFiles((FileFilter) pathname -> pathname.isFile() && pathname.getName().endsWith(".xml"));
if (backups != null && backups.length > 0) {
URL backupUrl = backups[backups.length - 1].toURL();
URL backupUrl = backups[backups.length - 1].toURI().toURL();
config = parser.parse(backupUrl, installLocation);
}
}
Expand Down Expand Up @@ -914,7 +914,7 @@ public static URL resolvePlatformURL(URL url, URL base_path_Location) throws IOE
if (base_path_Location == null) {
url = FileLocator.toFileURL(url);
File f = new File(url.getFile());
url = f.toURL();
url = f.toURI().toURL();
} else {
final String BASE = "platform:/base/";
final String CONFIG = "platform:/config/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SiteEntry(URL url, ISitePolicy policy) {
if (url.getProtocol().equals("file")) { //$NON-NLS-1$
try {
// TODO remove this when platform fixes local file url's
this.url = new File(url.getFile()).toURL();
this.url = new File(url.getFile()).toURI().toURL();
} catch (MalformedURLException e1) {
this.url = url;
}
Expand Down Expand Up @@ -278,7 +278,7 @@ private void detectFeatures() {
if (featureXML.lastModified() <= featuresChangeStamp &&
dir.lastModified() <= featuresChangeStamp)
continue;
URL featureURL = featureXML.toURL();
URL featureURL = featureXML.toURI().toURL();
FeatureEntry featureEntry = featureParser.parse(featureURL);
if (featureEntry != null)
addFeatureEntry(featureEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public static URL makeAbsolute(URL base, URL relativeLocation) {
try {
IPath absolutePath = IPath.fromOSString(base.getPath()).append(relativeLocation.getPath());
// File.toURL() is the best way to create a file: URL
return absolutePath.toFile().toURL();
return absolutePath.toFile().toURI().toURL();
} catch (MalformedURLException e) {
// cannot happen since we are building from two existing valid URLs
Utils.log(e.getLocalizedMessage());
Expand Down Expand Up @@ -488,7 +488,7 @@ public static String canonicalizeURL(String url) {
char[] chars = path.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
path = new String(chars);
return new File(path).toURL().toExternalForm();
return new File(path).toURI().toURL().toExternalForm();
}
} catch (MalformedURLException e) {
// default to original url
Expand Down
Loading