RFR: 8294241: Deprecate URL public constructors

Xue-Lei Andrew Fan xuelei at openjdk.org
Wed Oct 26 17:42:31 UTC 2022

On Wed, 26 Oct 2022 17:24:59 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> src/java.base/share/classes/java/net/URL.java line 852:
>>> 850:      * @since 20
>>> 851:      */
>>> 852:     public static URL fromURI(URI uri, URLStreamHandler streamHandler)
>> What do you think to have this method in URI instead: URI.toURL(URLStreamHandler), as there is an URI.toURL() method already?
> `URLStreamHandler` really belongs to `java.net.URL`, and is an implementation detail of the infrastructure/SPI that makes it possible to eventually call `URL::openConnection`. I do not think it would be appropriate to have such a method in `java.net.URI`. Dealing with `URLStreamHandler` is advanced usage and is not something that a regular developer will need to do, and it is better if it isn't too prominent.

I see your point.  It may be more appropriate if URI.toURL was designed as URL.fromURL.

I was wondering to have application developers a consistent way to get an URL instance.  Now there are two methods in different classes URI.toURL and URL.fromURI.  It might be easier to use the old URI.toURL form.

Never mind, it is just my personal preference.  It is fine to me to have a new URL.fromURI method.


PR: https://git.openjdk.org/jdk/pull/10874

More information about the security-dev mailing list