Skip to content

Commit 792799e

Browse files
committed
java.io.File.toURL() is deprecated and marked for removal. Replace it
with file.toURI().toURL(), where toURL() is called on a java.net.URI instance, which is not deprecated and handles encoding correctly.
1 parent 1ff6f01 commit 792799e

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/PlatformURLResourceConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static void startup(IPath root) {
104104
if (rootURL != null)
105105
return;
106106
try {
107-
rootURL = root.toFile().toURL();
107+
rootURL = root.toFile().toURI().toURL();
108108
} catch (MalformedURLException e) {
109109
// should never happen but if it does, the resource URL cannot be supported.
110110
return;

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private PlatformConfiguration(Location platformConfigLocation) throws CoreExcept
122122
// Retrieve install location with respect to given url if possible
123123
try {
124124
if (url != null && url.getProtocol().equals("file") && url.getPath().endsWith("configuration/org.eclipse.update/platform.xml")) {
125-
installLocation = IPath.fromOSString(url.getPath()).removeLastSegments(3).toFile().toURL();
125+
installLocation = IPath.fromOSString(url.getPath()).removeLastSegments(3).toFile().toURI().toURL();
126126
}
127127
} catch (Exception e) {
128128
//
@@ -853,7 +853,7 @@ private Configuration loadConfig(URL url, URL installLocation) throws Exception
853853
if (workingDir != null && workingDir.exists()) {
854854
File[] backups = workingDir.listFiles((FileFilter) pathname -> pathname.isFile() && pathname.getName().endsWith(".xml"));
855855
if (backups != null && backups.length > 0) {
856-
URL backupUrl = backups[backups.length - 1].toURL();
856+
URL backupUrl = backups[backups.length - 1].toURI().toURL();
857857
config = parser.parse(backupUrl, installLocation);
858858
}
859859
}
@@ -914,7 +914,7 @@ public static URL resolvePlatformURL(URL url, URL base_path_Location) throws IOE
914914
if (base_path_Location == null) {
915915
url = FileLocator.toFileURL(url);
916916
File f = new File(url.getFile());
917-
url = f.toURL();
917+
url = f.toURI().toURL();
918918
} else {
919919
final String BASE = "platform:/base/";
920920
final String CONFIG = "platform:/config/";

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/SiteEntry.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public SiteEntry(URL url, ISitePolicy policy) {
7171
if (url.getProtocol().equals("file")) { //$NON-NLS-1$
7272
try {
7373
// TODO remove this when platform fixes local file url's
74-
this.url = new File(url.getFile()).toURL();
74+
this.url = new File(url.getFile()).toURI().toURL();
7575
} catch (MalformedURLException e1) {
7676
this.url = url;
7777
}
@@ -278,7 +278,7 @@ private void detectFeatures() {
278278
if (featureXML.lastModified() <= featuresChangeStamp &&
279279
dir.lastModified() <= featuresChangeStamp)
280280
continue;
281-
URL featureURL = featureXML.toURL();
281+
URL featureURL = featureXML.toURI().toURL();
282282
FeatureEntry featureEntry = featureParser.parse(featureURL);
283283
if (featureEntry != null)
284284
addFeatureEntry(featureEntry);

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/Utils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public static URL makeAbsolute(URL base, URL relativeLocation) {
411411
try {
412412
IPath absolutePath = IPath.fromOSString(base.getPath()).append(relativeLocation.getPath());
413413
// File.toURL() is the best way to create a file: URL
414-
return absolutePath.toFile().toURL();
414+
return absolutePath.toFile().toURI().toURL();
415415
} catch (MalformedURLException e) {
416416
// cannot happen since we are building from two existing valid URLs
417417
Utils.log(e.getLocalizedMessage());
@@ -488,7 +488,7 @@ public static String canonicalizeURL(String url) {
488488
char[] chars = path.toCharArray();
489489
chars[0] = Character.toLowerCase(chars[0]);
490490
path = new String(chars);
491-
return new File(path).toURL().toExternalForm();
491+
return new File(path).toURI().toURL().toExternalForm();
492492
}
493493
} catch (MalformedURLException e) {
494494
// default to original url

0 commit comments

Comments
 (0)