-
Notifications
You must be signed in to change notification settings - Fork 209
Replace deprecated File.toURL() #2937
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
base: master
Are you sure you want to change the base?
Conversation
38b504b
to
05512b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this.
This contributes to the large effort of eclipse-platform/eclipse.platform#35.
...ui.css.core/src/org/eclipse/e4/ui/css/core/util/impl/resources/HttpResourcesLocatorImpl.java
Outdated
Show resolved
Hide resolved
@@ -540,13 +540,13 @@ private static URL getPersistenceUrl(URL baseUrl, boolean create) { | |||
} | |||
|
|||
// make sure the file exists | |||
url = new URL(dir.toURL(), PERS_FILENAME); | |||
url = new URL(dir.toURI().toURL(), PERS_FILENAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the callers, the method getPersistenceUrl()
should directly return a File or even better a Path.
In general the URL to File/Path conversion done here and in the caller are all actually not robust and only work by chance, i.e. in case the URL does not contain encoded characters.
Instead you should extract the Path
(File
would also work, but Path is more powerful) using Path.of(URIUtil.toURI(baseUrl))
and then perform all resolution and existance checks directly on the Path/File API and never convert back to URL or URI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the implementation you were referring to?
try {
// make sure the directory exists
URL url = new URL(baseUrl, PERS_FOLDER);
File dir = new File(url.getFile());
if (!dir.exists() && (!create || !dir.mkdir())) {
return null;
}
// make sure the file exists
Path p = Path.of(URIUtil.toURI(baseUrl.getPath() + File.pathSeparator + PERS_FILENAME));
if (!Files.exists(p) && (!create || !p.toFile().createNewFile())) {
return null;
}
return p.toUri().toURL();
} catch (IOException e) {
// cannot log because instance area has not been set
return null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the caller I was referring to.
05512b9
to
f36bc50
Compare
This pull request changes some projects for the first time in this development cycle.
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
Further information are available in Common Build Issues - Missing version increments. |
a0cfbc8
to
fa3c80c
Compare
231a35c
to
20d1219
Compare
Thank you @elsazac for the update. but sadly that will probably not land anymore in this release cycle. But I plan to have this ready early next cycle and I suggest to put this on hold for that time. I'll keep you posted once that is ready, but also invite you to monitor that PR. |
java.io.File.toURL()
is deprecated and marked for removal. Replace it withfile.toURI().toURL()
, wheretoURL()
is called on ajava.net.URI
instance, which is not deprecated and handles encoding correctly.