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

Conversation

elsazac
Copy link
Member

@elsazac elsazac commented Apr 30, 2025

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.

@eclipse-platform-bot
Copy link
Contributor

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

update/org.eclipse.update.configurator/META-INF/MANIFEST.MF

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From 694884198d643a9fe071043683f574083c0ede0c Mon Sep 17 00:00:00 2001
From: Eclipse Platform Bot <[email protected]>
Date: Wed, 30 Apr 2025 10:44:45 +0000
Subject: [PATCH] Version bump(s) for 4.36 stream


diff --git a/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF b/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF
index 5f045c7318..f1a5deb034 100644
--- a/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF
+++ b/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF
@@ -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
-- 
2.49.0

Further information are available in Common Build Issues - Missing version increments.

Copy link
Contributor

github-actions bot commented Apr 30, 2025

Test Results

 1 758 files  ±0   1 758 suites  ±0   1h 28m 50s ⏱️ - 4m 24s
 4 173 tests ±0   4 150 ✅ ±0   23 💤 ±0  0 ❌ ±0 
13 119 runs  ±0  12 952 ✅ ±0  167 💤 ±0  0 ❌ ±0 

Results for commit 85b56c2. ± Comparison against base commit 9bbb5b0.

♻️ This comment has been updated with latest results.

@elsazac elsazac force-pushed the toURL_ePlatform branch from f419d12 to 686be55 Compare May 5, 2025 06:25
elsazac and others added 2 commits May 6, 2025 17:22
with file.toURI().toURL(), where toURL() is called on a java.net.URI
instance, which is not deprecated and handles encoding correctly.
@elsazac elsazac force-pushed the toURL_ePlatform branch from 686be55 to 85b56c2 Compare May 6, 2025 11:52
@@ -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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@HannesWell
How did you identify that this URL might be accessed by client code outside the platform? Was that based on the method being public or something specific in the code? Just trying to understand the scenario better.

@merks
Copy link
Contributor

merks commented May 6, 2025

Such changes are really scary. You would be shocked how many places expect the url not to be properly encoded. Unless we have extensive tests with paths with spaces, the % character, and non-ascii characters I can pretty much guarantee you that things will go wrong.

Don’t do this in isolation.

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.

5 participants