Integrated: 8294241: Deprecate URL public constructors

Daniel Fuchs dfuchs at
Thu Nov 3 17:22:28 UTC 2022

On Wed, 26 Oct 2022 16:00:56 GMT, Daniel Fuchs <dfuchs at> wrote:

> Deprecate URL constructors. Developers are encouraged to use `` to parse or construct any URL.
> The `` class does not itself encode or decode any URL components according to the escaping mechanism defined in RFC2396. It is the responsibility of the caller to encode any fields, which need to be escaped prior to calling URL, and also to decode any escaped fields, that are returned from URL. 
> This has lead to many issues in the past.  Indeed, if used improperly, there is no guarantee that `URL::toString` or `URL::toExternalForm` will lead to a URL string that can be parsed back into the same URL. This can lead to constructing misleading URLs. Another issue is with `equals()` and `hashCode()` which may have to perform a lookup, and do not take encoding/escaping into account.
> In Java SE 1.4 a new class, ``, has been added to mitigate some of the shortcoming of ``. Conversion methods to create a URL from a URI were also added. However, it was left up to the developers to use ``, or not. This RFE proposes to deprecate all public constructors of ``, in order to provide a stronger warning about their potential misuses. To construct a URL, using `URI::toURL` should be preferred.
> In order to provide an alternative to the constructors that take a stream handler as parameter, a new factory method `URL::fromURI(,` is provided as  part of this change.
> Places in the JDK code base that were constructing `` have been temporarily annotated with `@SuppressWarnings("deprecation")`.  Some related issues will be logged to revisit the calling code.
> The CSR can be reviewed here:

This pull request has now been integrated.

Changeset: 4338f527
Author:    Daniel Fuchs <dfuchs at>
Stats:     853 lines in 82 files changed: 707 ins; 5 del; 141 mod

8294241: Deprecate URL public constructors

Reviewed-by: joehw, prr, alanb, aefimov, michaelm



More information about the compiler-dev mailing list