Introduce robust URL to java.nio.file.Path conversion #691
+93
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Converting a URL into a
Path
orFile
is not a trivial task, especially since URLs are often malformed and therefore the straight forward wayPath.of(url.toURI())
ornew File(url.toURI())
lead to aURISyntaxException
being thrown. Therefore multiple different workarounds are used throughout the SDK, e.g.Path.of(url.getPath())
orPath.of(url.getFile())
, but they are again have their problems.This PR suggest a new utility method in the
URIUtil
that is capable of all the different conversion methods and workarounds and has the goal to reliably convertfile
-URLs intojava.nio.file.Path
s regardless of if the URL is malformed or perfectly complying to the standard.This could also help for eclipse-platform/eclipse.platform#35 because one does not have to rely on malformed URLs anymore if they are just passed around internally (URLs displayed to the user are another topic).