You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since all URL constructors are deprecated starting with Java 20, we should stop using them in order to allow Spring Framework to be built using Java 20.
In addition, the rationale for deprecating those constructors (which is more important than the actual deprecation) is applicable today.
For full details, see the Constructing instances of URL section of the URL Javadoc. The API Note also provides valuable advice regarding correct usage of File, Path, URI, and URL.
This turns out to be rather involved due to the differences between URI and URL rules and the restricted behavior of the java.net.URI#toURL() method. As a first step, #29486 prepares the codebase for alternative URL construction arrangements in 6.0; a full replacement/reimplementation of URL construction rules from user-supplied Strings is likely to come in 6.1 then.
With a combination of URI construction from a cleaned path and subsequent defensive URL conversion, all our tests pass. This is still rather involved but seems to be equivalent for our common purposes now.
Corresponding code is available in UrlResource(String), ResourceUtils.toURL(String) and ResourceUtils.toRelativeURL in comment blocks now, for an easy switch in 6.1 (or whenever we find it appropriate).
Activity
jhoeller commentedon Nov 14, 2022
This turns out to be rather involved due to the differences between URI and URL rules and the restricted behavior of the
java.net.URI#toURL()method. As a first step, #29486 prepares the codebase for alternative URL construction arrangements in 6.0; a full replacement/reimplementation of URL construction rules from user-supplied Strings is likely to come in 6.1 then.jhoeller commentedon Nov 14, 2022
With a combination of URI construction from a cleaned path and subsequent defensive URL conversion, all our tests pass. This is still rather involved but seems to be equivalent for our common purposes now.
Corresponding code is available in
UrlResource(String),ResourceUtils.toURL(String)andResourceUtils.toRelativeURLin comment blocks now, for an easy switch in 6.1 (or whenever we find it appropriate).Equivalent code without java.net.URL constructor in comment blocks
sbrannen commentedon Nov 28, 2022
Update: added a section with additional resources regarding changes in behavior in URL constructors beginning with Java 20.
Relax relative path existence assertion for parsed URIs
Avoid use of java.net.URL constructors (for JDK 20 compatibility)