diff --git a/src/java.base/share/classes/java/io/File.java b/src/java.base/share/classes/java/io/File.java
index 8f1e88219fecd..2e3b8b0a9e480 100644
--- a/src/java.base/share/classes/java/io/File.java
+++ b/src/java.base/share/classes/java/io/File.java
@@ -694,7 +694,9 @@ public URL toURL() throws MalformedURLException {
if (isInvalid()) {
throw new MalformedURLException("Invalid file path");
}
- return new URL("file", "", slashify(getAbsolutePath(), isDirectory()));
+ @SuppressWarnings("deprecation")
+ var result = new URL("file", "", slashify(getAbsolutePath(), isDirectory()));
+ return result;
}
/**
diff --git a/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java b/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
index c0988050ef07a..c959816dadfbb 100644
--- a/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
+++ b/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -184,6 +184,7 @@ private Socket doTunnel(String urlString, int connectTimeout)
throws IOException
{
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(server, port));
+ @SuppressWarnings("deprecation")
URL destURL = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) destURL.openConnection(proxy);
conn.setConnectTimeout(connectTimeout);
diff --git a/src/java.base/share/classes/java/net/JarURLConnection.java b/src/java.base/share/classes/java/net/JarURLConnection.java
index 232a548e0a756..2c2734b08d7ba 100644
--- a/src/java.base/share/classes/java/net/JarURLConnection.java
+++ b/src/java.base/share/classes/java/net/JarURLConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -172,14 +172,17 @@ private void parseSpecs(URL url) throws MalformedURLException {
throw new MalformedURLException("no !/ found in url spec:" + spec);
}
- jarFileURL = new URL(spec.substring(0, separator++));
+ @SuppressWarnings("deprecation")
+ var _unused = jarFileURL = new URL(spec.substring(0, separator++));
+
/*
* The url argument may have had a runtime fragment appended, so
* we need to add a runtime fragment to the jarFileURL to enable
* runtime versioning when the underlying jar file is opened.
*/
if ("runtime".equals(url.getRef())) {
- jarFileURL = new URL(jarFileURL, "#runtime");
+ @SuppressWarnings("deprecation")
+ var _unused2 = jarFileURL = new URL(jarFileURL, "#runtime");
}
entryName = null;
diff --git a/src/java.base/share/classes/java/net/URI.java b/src/java.base/share/classes/java/net/URI.java
index 9b42c0347ac3b..b532d41059e1d 100644
--- a/src/java.base/share/classes/java/net/URI.java
+++ b/src/java.base/share/classes/java/net/URI.java
@@ -1133,7 +1133,7 @@ public URI relativize(URI uri) {
* or if some other error occurred while constructing the URL
*/
public URL toURL() throws MalformedURLException {
- return URL.fromURI(this);
+ return URL.of(this, null);
}
// -- Component access methods --
diff --git a/src/java.base/share/classes/java/net/URL.java b/src/java.base/share/classes/java/net/URL.java
index f247bfebb63d2..56793be1e974f 100644
--- a/src/java.base/share/classes/java/net/URL.java
+++ b/src/java.base/share/classes/java/net/URL.java
@@ -129,6 +129,26 @@
* the protocol, host name, or port number is missing, the value is
* inherited from the fully specified URL. The file component must be
* specified. The optional fragment is not inherited.
+ *
+ *
Constructing instances of {@code URL}
+ *
+ * The {@code java.net.URL} constructors are deprecated.
+ * Developers are encouraged to use {@link URI java.net.URI} to parse
+ * or construct a {@code URL}. In cases where an instance of {@code
+ * java.net.URL} is needed to open a connection, {@link URI} can be used
+ * to construct or parse the URL string, possibly calling {@link
+ * URI#parseServerAuthority()} to validate that the authority component
+ * can be parsed as a server-based authority, and then calling
+ * {@link URI#toURL()} to create the {@code URL} instance.
+ *
+ * The URL constructors are specified to throw
+ * {@link MalformedURLException} but the actual parsing/validation
+ * that is performed is implementation dependent. Some parsing/validation
+ * may be delayed until later, when the underlying {@linkplain
+ * URLStreamHandler stream handler's implementation} is called.
+ * Being able to construct an instance of {@code URL} doesn't
+ * provide any guarantee about its conformance to the URL
+ * syntax specification.
*
* The URL class does not itself encode or decode any URL components
* according to the escaping mechanism defined in RFC2396. It is the
@@ -152,6 +172,7 @@
*
* @apiNote
*
+ *
* Applications working with file paths and file URIs should take great
* care to use the appropriate methods to convert between the two.
* The {@link Path#of(URI)} factory method and the {@link File#File(URI)}
@@ -164,6 +185,11 @@
* from the direct string representation of a {@code File} or {@code Path}
* instance.
*
+ * Before constructing a {@code URL} from a {@code URI}, and depending
+ * on the protocol involved, applications should consider validating
+ * whether the URI authority {@linkplain URI#parseServerAuthority()
+ * can be parsed as server-based}.
+ *
* Some components of a URL or URI, such as userinfo, may
* be abused to construct misleading URLs or URIs. Applications
* that deal with URLs or URIs should take into account
@@ -373,7 +399,11 @@ public final class URL implements java.io.Serializable {
* @see java.net.URLStreamHandler
* @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
* java.lang.String)
+ * @deprecated Use {@link URI#toURL()} to construct an instance of URL. See the note on
+ * constructor deprecation for more
+ * details.
*/
+ @Deprecated(since = "20")
public URL(String protocol, String host, int port, String file)
throws MalformedURLException
{
@@ -399,7 +429,11 @@ public URL(String protocol, String host, int port, String file)
* rejects, or is known to reject, the {@code URL}
* @see java.net.URL#URL(java.lang.String, java.lang.String,
* int, java.lang.String)
+ * @deprecated Use {@link URI#toURL()} to construct an instance of URL. See the note on
+ * constructor deprecation for more
+ * details.
*/
+ @Deprecated(since = "20")
public URL(String protocol, String host, String file)
throws MalformedURLException {
this(protocol, host, -1, file);
@@ -446,7 +480,13 @@ public URL(String protocol, String host, String file)
* java.lang.String)
* @see SecurityManager#checkPermission
* @see java.net.NetPermission
+ * @deprecated
+ * Use {@link #of(URI, URLStreamHandler)} to construct an instance of URL
+ * associated with a custom protocol handler.
+ * See the note on constructor deprecation
+ * for more details.
*/
+ @Deprecated(since = "20")
public URL(String protocol, String host, int port, String file,
URLStreamHandler handler) throws MalformedURLException {
if (handler != null) {
@@ -533,7 +573,11 @@ public URL(String protocol, String host, int port, String file,
* URLStreamHandler#parseURL parseURL method} throws
* {@code IllegalArgumentException}
* @see java.net.URL#URL(java.net.URL, java.lang.String)
+ * @deprecated Use {@link URI#toURL()} to construct an instance of URL. See the note on
+ * constructor deprecation for more
+ * details.
*/
+ @Deprecated(since = "20")
public URL(String spec) throws MalformedURLException {
this(null, spec);
}
@@ -593,7 +637,11 @@ public URL(String spec) throws MalformedURLException {
* @see java.net.URLStreamHandler
* @see java.net.URLStreamHandler#parseURL(java.net.URL,
* java.lang.String, int, int)
+ * @deprecated Use {@link URI#toURL()} to construct an instance of URL. See the note on
+ * constructor deprecation for more
+ * details.
*/
+ @Deprecated(since = "20")
public URL(URL context, String spec) throws MalformedURLException {
this(context, spec, null);
}
@@ -626,7 +674,13 @@ public URL(URL context, String spec) throws MalformedURLException {
* @see java.net.URLStreamHandler
* @see java.net.URLStreamHandler#parseURL(java.net.URL,
* java.lang.String, int, int)
+ * @deprecated
+ * Use {@link #of(URI, URLStreamHandler)} to construct an instance of URL
+ * associated with a custom protocol handler.
+ * See the note on constructor deprecation
+ * for more details.
*/
+ @Deprecated(since = "20")
public URL(URL context, String spec, URLStreamHandler handler)
throws MalformedURLException
{
@@ -748,23 +802,70 @@ public URL(URL context, String spec, URLStreamHandler handler)
}
/**
- * Creates a URL from a URI, as if by invoking {@code uri.toURL()}.
+ * Creates a URL from a URI, as if by invoking {@code uri.toURL()}, but
+ * associating it with the given {@code URLStreamHandler}, if allowed.
+ *
+ * @apiNote
+ * Applications should consider performing additional integrity
+ * checks before constructing a {@code URL} and opening a connection.
+ * See the API note in the class level API
+ * documentation.
+ *
+ * @implSpec The implementation of this method includes calling the {@link
+ * URLStreamHandler#parseURL(URL, String, int, int) parseURL} method on the
+ * selected handler.
+ *
+ * @param uri the {@code URI} from which the returned {@code URL} should
+ * be built
+ * @param handler a custom protocol stream handler for
+ * the returned {@code URL}. Can be {@code null},
+ * in which case the default stream handler for
+ * the protocol if any, will be used.
+ *
+ * @return a new {@code URL} instance created from the given {@code URI}
+ * and associated with the given {@code URLStreamHandler}, if any
+ *
+ * @throws NullPointerException if {@code uri} is {@code null}
+ *
+ * @throws IllegalArgumentException if no protocol is specified
+ * (the {@linkplain URI#getScheme() uri scheme} is {@code null}), or
+ * if the {@code URLStreamHandler} is not {@code null} and can not be
+ * set for the given protocol
+ *
+ * @throws MalformedURLException if an unknown protocol is found,
+ * or the given URI fails to comply with the specific
+ * syntax of the associated protocol, or the
+ * underlying stream handler's {@linkplain
+ * URLStreamHandler#parseURL(URL, String, int, int)
+ * parseURL method} throws {@code IllegalArgumentException}
+ *
+ * @throws SecurityException
+ * if a security manager exists and its
+ * {@code checkPermission} method doesn't allow
+ * specifying a stream handler
*
* @see java.net.URI#toURL()
+ *
+ * @since 20
*/
- static URL fromURI(URI uri) throws MalformedURLException {
+ public static URL of(URI uri, URLStreamHandler handler)
+ throws MalformedURLException {
if (!uri.isAbsolute()) {
throw new IllegalArgumentException("URI is not absolute");
}
+
String protocol = uri.getScheme();
+ // fast path for canonical jrt:/... URLs
+ //
// In general we need to go via Handler.parseURL, but for the jrt
// protocol we enforce that the Handler is not overridable and can
// optimize URI to URL conversion.
//
// Case-sensitive comparison for performance; malformed protocols will
// be handled correctly by the slow path.
- if (protocol.equals("jrt") && !uri.isOpaque()
+ if (handler == null && protocol.equals("jrt") && !uri.isOpaque()
+ && uri.getRawAuthority() == null
&& uri.getRawFragment() == null) {
String query = uri.getRawQuery();
@@ -780,9 +881,28 @@ static URL fromURI(URI uri) throws MalformedURLException {
int port = uri.getPort();
return new URL("jrt", host, port, file, null);
- } else {
- return new URL((URL)null, uri.toString(), null);
}
+
+ // slow path (will work for non-canonical forms of jrt: too)
+
+ if ("url".equalsIgnoreCase(protocol)) {;
+ String uristr = uri.toString();
+ try {
+ URI inner = new URI(uristr.substring(4));
+ if (inner.isAbsolute()) {
+ protocol = inner.getScheme();
+ }
+ } catch (URISyntaxException use) {
+ throw new MalformedURLException(use.getMessage());
+ }
+ }
+
+ if (handler != null && !isOverrideable(protocol)) {
+ throw new IllegalArgumentException("Can't override URLStreamHandler for protocol "
+ + protocol);
+ }
+
+ return new URL((URL)null, uri.toString(), handler);
}
/*
diff --git a/src/java.base/share/classes/java/security/Security.java b/src/java.base/share/classes/java/security/Security.java
index dcfe3b4d6bbe4..257dc172ee2af 100644
--- a/src/java.base/share/classes/java/security/Security.java
+++ b/src/java.base/share/classes/java/security/Security.java
@@ -25,6 +25,7 @@
package java.security;
+import java.net.MalformedURLException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.io.*;
@@ -135,10 +136,10 @@ private static boolean loadProps(File masterFile, String extraPropFile, boolean
File propFile = new File(extraPropFile);
URL propURL;
if (propFile.exists()) {
- propURL = new URL
+ propURL = newURL
("file:" + propFile.getCanonicalPath());
} else {
- propURL = new URL(extraPropFile);
+ propURL = newURL(extraPropFile);
}
is = propURL.openStream();
@@ -993,4 +994,9 @@ public static Set getAlgorithms(String serviceName) {
}
return Collections.unmodifiableSet(result);
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
}
diff --git a/src/java.base/share/classes/javax/crypto/JceSecurity.java.template b/src/java.base/share/classes/javax/crypto/JceSecurity.java.template
index 69ca07dbc6d92..220dd6f1f5c64 100644
--- a/src/java.base/share/classes/javax/crypto/JceSecurity.java.template
+++ b/src/java.base/share/classes/javax/crypto/JceSecurity.java.template
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -243,7 +243,8 @@ final class JceSecurity {
static {
try {
- NULL_URL = new URL("http://null.oracle.com/");
+ @SuppressWarnings("deprecation")
+ var _unused = NULL_URL = new URL("http://null.oracle.com/");
} catch (Exception e) {
throw new RuntimeException(e);
}
diff --git a/src/java.base/share/classes/javax/crypto/ProviderVerifier.java b/src/java.base/share/classes/javax/crypto/ProviderVerifier.java
index c7344b852dee7..cbfd02c32f4f7 100644
--- a/src/java.base/share/classes/javax/crypto/ProviderVerifier.java
+++ b/src/java.base/share/classes/javax/crypto/ProviderVerifier.java
@@ -91,6 +91,7 @@ void verify() throws IOException {
// If the protocol of jarURL isn't "jar", we should
// construct a JAR URL so we can open a JarURLConnection
// for verifying this provider.
+ @SuppressWarnings("deprecation")
final URL url = jarURL.getProtocol().equalsIgnoreCase("jar")?
jarURL : new URL("jar:" + jarURL + "!/");
diff --git a/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java b/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
index 71c09fc7b6a6f..7b49189418dba 100644
--- a/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
+++ b/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
@@ -493,6 +493,7 @@ public Loader run() throws IOException {
isDefaultJarHandler(url) &&
file.endsWith("!/")) {
// extract the nested URL
+ @SuppressWarnings("deprecation")
URL nestedUrl = new URL(file.substring(0, file.length() - 2));
return new JarLoader(nestedUrl, jarHandler, lmap, acc);
} else {
@@ -605,7 +606,8 @@ final URL getBaseURL() {
URL findResource(final String name, boolean check) {
URL url;
try {
- url = new URL(base, ParseUtil.encodePath(name, false));
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(base, ParseUtil.encodePath(name, false));
} catch (MalformedURLException e) {
return null;
}
@@ -641,7 +643,8 @@ URL findResource(final String name, boolean check) {
Resource getResource(final String name, boolean check) {
final URL url;
try {
- url = new URL(base, ParseUtil.encodePath(name, false));
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(base, ParseUtil.encodePath(name, false));
} catch (MalformedURLException e) {
return null;
}
@@ -729,7 +732,7 @@ private JarLoader(URL url, URLStreamHandler jarHandler,
@SuppressWarnings("removal") AccessControlContext acc)
throws IOException
{
- super(new URL("jar", "", -1, url + "!/", jarHandler));
+ super(newURL("jar", "", -1, url + "!/", jarHandler));
csu = url;
handler = jarHandler;
lmap = loaderMap;
@@ -738,6 +741,13 @@ private JarLoader(URL url, URLStreamHandler jarHandler,
ensureOpen();
}
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String protocol, String host, int port, String file, URLStreamHandler handler)
+ throws MalformedURLException
+ {
+ return new URL(protocol, host, port, file, handler);
+ }
+
@Override
public void close () throws IOException {
// closing is synchronized at higher level
@@ -782,6 +792,7 @@ public Void run() throws IOException {
// URL until we actually need to try to load something from them.
for (int i = 0; i < jarfiles.length; i++) {
try {
+ @SuppressWarnings("deprecation")
URL jarURL = new URL(csu, jarfiles[i]);
// If a non-null loader already exists, leave it alone.
String urlNoFragString = URLUtil.urlNoFragString(jarURL);
@@ -829,6 +840,7 @@ private JarFile getJarFile(URL url) throws IOException {
return checkJar(new JarFile(new File(p.getPath()), true, ZipFile.OPEN_READ,
JarFile.runtimeVersion()));
}
+ @SuppressWarnings("deprecation")
URLConnection uc = (new URL(getBaseURL(), "#runtime")).openConnection();
uc.setRequestProperty(USER_AGENT_JAVA_VERSION, JAVA_VERSION);
JarFile jarFile = ((JarURLConnection)uc).getJarFile();
@@ -862,7 +874,8 @@ Resource checkResource(final String name, boolean check,
} else {
nm = name;
}
- url = new URL(getBaseURL(), ParseUtil.encodePath(nm, false));
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(getBaseURL(), ParseUtil.encodePath(nm, false));
if (check) {
URLClassPath.check(url);
}
@@ -993,7 +1006,8 @@ Resource getResource(final String name, boolean check,
final URL url;
try{
- url = new URL(csu, jarName);
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(csu, jarName);
String urlNoFragString = URLUtil.urlNoFragString(url);
if ((newLoader = (JarLoader)lmap.get(urlNoFragString)) == null) {
/* no loader has been set up for this jar file
@@ -1116,6 +1130,7 @@ private static URL[] parseClassPath(URL base, String value)
int i = 0;
while (st.hasMoreTokens()) {
String path = st.nextToken();
+ @SuppressWarnings("deprecation")
URL url = DISABLE_CP_URL_CHECK ? new URL(base, path) : tryResolve(base, path);
if (url != null) {
urls[i] = url;
@@ -1152,6 +1167,7 @@ static URL tryResolve(URL base, String input) throws MalformedURLException {
* @throws MalformedURLException
*/
static URL tryResolveFile(URL base, String input) throws MalformedURLException {
+ @SuppressWarnings("deprecation")
URL retVal = new URL(base, input);
if (input.indexOf(':') >= 0 &&
!"file".equalsIgnoreCase(retVal.getProtocol())) {
@@ -1173,6 +1189,7 @@ static URL tryResolveFile(URL base, String input) throws MalformedURLException {
static URL tryResolveNonFile(URL base, String input) throws MalformedURLException {
String child = input.replace(File.separatorChar, '/');
if (isRelative(child)) {
+ @SuppressWarnings("deprecation")
URL url = new URL(base, child);
String bp = base.getPath();
String urlp = url.getPath();
@@ -1217,7 +1234,8 @@ private FileLoader(URL url) throws IOException {
String path = url.getFile().replace('/', File.separatorChar);
path = ParseUtil.decode(path);
dir = (new File(path)).getCanonicalFile();
- normalizedBase = new URL(getBaseURL(), ".");
+ @SuppressWarnings("deprecation")
+ var _unused = normalizedBase = new URL(getBaseURL(), ".");
}
/*
@@ -1236,7 +1254,8 @@ URL findResource(final String name, boolean check) {
Resource getResource(final String name, boolean check) {
final URL url;
try {
- url = new URL(getBaseURL(), ParseUtil.encodePath(name, false));
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(getBaseURL(), ParseUtil.encodePath(name, false));
if (url.getFile().startsWith(normalizedBase.getFile()) == false) {
// requested resource had ../..'s in path
diff --git a/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java b/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java
index 607357352f914..ce837027faa26 100644
--- a/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java
+++ b/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -454,7 +454,9 @@ public String getName() {
public URL getURL() {
String encodedPath = ParseUtil.encodePath(name, false);
try {
- return new URL("jar:" + csURL + "!/" + encodedPath);
+ @SuppressWarnings("deprecation")
+ var result = new URL("jar:" + csURL + "!/" + encodedPath);
+ return result;
} catch (MalformedURLException e) {
return null;
}
diff --git a/src/java.base/share/classes/sun/net/util/URLUtil.java b/src/java.base/share/classes/sun/net/util/URLUtil.java
index a3cf4d7fb16a4..6d80825e901c7 100644
--- a/src/java.base/share/classes/sun/net/util/URLUtil.java
+++ b/src/java.base/share/classes/sun/net/util/URLUtil.java
@@ -95,6 +95,7 @@ public static Permission getConnectPermission(URL url) throws IOException {
String urlString = url.toString();
int bangPos = urlString.indexOf("!/");
urlString = urlString.substring(4, bangPos > -1 ? bangPos : urlString.length());
+ @SuppressWarnings("deprecation")
URL u = new URL(urlString);
return getURLConnectPermission(u);
// If protocol is HTTP or HTTPS than use URLPermission object
diff --git a/src/java.base/share/classes/sun/net/www/ParseUtil.java b/src/java.base/share/classes/sun/net/www/ParseUtil.java
index d84fa82b19e42..def688ad96a3a 100644
--- a/src/java.base/share/classes/sun/net/www/ParseUtil.java
+++ b/src/java.base/share/classes/sun/net/www/ParseUtil.java
@@ -239,7 +239,9 @@ public static URL fileToEncodedURL(File file)
if (!path.endsWith("/") && file.isDirectory()) {
path = path + "/";
}
- return new URL("file", "", path);
+ @SuppressWarnings("deprecation")
+ var result = new URL("file", "", path);
+ return result;
}
public static java.net.URI toURI(URL url) {
diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
index 0e8584eece5c8..36f5e3cb37fcd 100644
--- a/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
+++ b/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
@@ -987,7 +987,7 @@ public static InputStream openConnectionCheckRedirects(URLConnection c)
String loc = http.getHeaderField("Location");
URL target = null;
if (loc != null) {
- target = new URL(base, loc);
+ target = newURL(base, loc);
}
http.disconnect();
if (target == null
@@ -1885,7 +1885,7 @@ private InputStream getInputStream0() throws IOException {
String path = tok.nextToken();
try {
/* path could be an abs_path or a complete URI */
- URL u = new URL (url, path);
+ URL u = newURL (url, path);
DigestAuthentication d = new DigestAuthentication (
false, u, realm, "Digest", pw,
digestparams, srv.authenticatorKey);
@@ -2502,6 +2502,7 @@ public InetAddress run()
if (ret == null && defaultAuth != null
&& defaultAuth.schemeSupported(scheme)) {
try {
+ @SuppressWarnings("deprecation")
URL u = new URL("http", host, port, "/");
String a = defaultAuth.authString(u, scheme, realm);
if (a != null) {
@@ -2616,7 +2617,7 @@ private AuthenticationInfo getServerAuthentication(AuthenticationHeader authhdr)
if (NTLMAuthenticationProxy.supported) {
URL url1;
try {
- url1 = new URL (url, "/"); /* truncate the path */
+ url1 = newURL (url, "/"); /* truncate the path */
} catch (Exception e) {
url1 = url;
}
@@ -2774,14 +2775,14 @@ private boolean followRedirect() throws IOException {
URL locUrl;
try {
- locUrl = new URL(loc);
+ locUrl = newURL(loc);
if (!url.getProtocol().equalsIgnoreCase(locUrl.getProtocol())) {
return false;
}
} catch (MalformedURLException mue) {
- // treat loc as a relative URI to conform to popular browsers
- locUrl = new URL(url, loc);
+ // treat loc as a relative URI to conform to popular browsers
+ locUrl = newURL(url, loc);
}
final URL locUrl0 = locUrl;
@@ -3994,6 +3995,16 @@ public void close() throws IOException {
}
}
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(URL context, String spec) throws MalformedURLException {
+ return new URL(context, spec);
+ }
}
/** An input stream that just returns EOF. This is for
diff --git a/src/java.base/share/classes/sun/net/www/protocol/jar/Handler.java b/src/java.base/share/classes/sun/net/www/protocol/jar/Handler.java
index 48381c8a276c3..2884f825b8439 100644
--- a/src/java.base/share/classes/sun/net/www/protocol/jar/Handler.java
+++ b/src/java.base/share/classes/sun/net/www/protocol/jar/Handler.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -78,8 +78,8 @@ protected boolean sameFile(URL u1, URL u2) {
URL enclosedURL1 = null, enclosedURL2 = null;
try {
- enclosedURL1 = new URL(file1.substring(0, sep1));
- enclosedURL2 = new URL(file2.substring(0, sep2));
+ enclosedURL1 = newURL(file1.substring(0, sep1));
+ enclosedURL2 = newURL(file2.substring(0, sep2));
} catch (MalformedURLException unused) {
return super.sameFile(u1, u2);
}
@@ -108,7 +108,7 @@ protected int hashCode(URL u) {
URL enclosedURL = null;
String fileWithoutEntry = file.substring(0, sep);
try {
- enclosedURL = new URL(fileWithoutEntry);
+ enclosedURL = newURL(fileWithoutEntry);
h += enclosedURL.hashCode();
} catch (MalformedURLException unused) {
h += fileWithoutEntry.hashCode();
@@ -179,7 +179,7 @@ private String parseAbsoluteSpec(String spec) {
// test the inner URL
try {
String innerSpec = spec.substring(0, index - 1);
- new URL(innerSpec);
+ newURL(innerSpec);
} catch (MalformedURLException e) {
throw new NullPointerException("invalid url: " +
spec + " (" + e + ")");
@@ -259,4 +259,9 @@ private static String doCanonicalize(String file) {
return file;
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
}
diff --git a/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java b/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java
index f8b10485f5778..b4cd98870ca23 100644
--- a/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java
+++ b/src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -166,6 +166,7 @@ public Permission getPermission() {
/**
* Returns a jrt URL for the given module and resource name.
*/
+ @SuppressWarnings("deprecation")
private static URL toJrtURL(String module, String name) {
try {
return new URL("jrt:/" + module + "/" + name);
@@ -177,6 +178,7 @@ private static URL toJrtURL(String module, String name) {
/**
* Returns a jrt URL for the given module.
*/
+ @SuppressWarnings("deprecation")
private static URL toJrtURL(String module) {
try {
return new URL("jrt:/" + module);
diff --git a/src/java.base/share/classes/sun/security/provider/ConfigFile.java b/src/java.base/share/classes/sun/security/provider/ConfigFile.java
index ae72c9ad6ad32..775e36c61baa6 100644
--- a/src/java.base/share/classes/sun/security/provider/ConfigFile.java
+++ b/src/java.base/share/classes/sun/security/provider/ConfigFile.java
@@ -256,7 +256,7 @@ private void init() throws IOException {
URL configURL;
try {
- configURL = new URL(extra_config);
+ configURL = newURL(extra_config);
} catch (MalformedURLException mue) {
File configFile = new File(extra_config);
if (configFile.exists()) {
@@ -293,7 +293,7 @@ private void init() throws IOException {
if (debugConfig != null) {
debugConfig.println("\tReading config: " + config_url);
}
- init(new URL(config_url), newConfig);
+ init(newURL(config_url), newConfig);
initialized = true;
} catch (PropertyExpander.ExpandException peee) {
throw ioException("Unable.to.properly.expand.config",
@@ -669,4 +669,9 @@ private IOException ioException(String resourceKey, Object... args) {
return new IOException(form.format(args));
}
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
}
diff --git a/src/java.base/share/classes/sun/security/provider/PolicyFile.java b/src/java.base/share/classes/sun/security/provider/PolicyFile.java
index 640fb63dd259e..f69f513dc9fcf 100644
--- a/src/java.base/share/classes/sun/security/provider/PolicyFile.java
+++ b/src/java.base/share/classes/sun/security/provider/PolicyFile.java
@@ -414,7 +414,7 @@ public Boolean run() {
policyURL = ParseUtil.fileToEncodedURL
(new File(policyFile.getCanonicalPath()));
} else {
- policyURL = new URL(extra_policy);
+ policyURL = newURL(extra_policy);
}
if (debug != null) {
debug.println("reading "+policyURL);
@@ -672,7 +672,7 @@ private CodeSource getCodeSource(PolicyParser.GrantEntry ge, KeyStore keyStore,
URL location;
if (ge.codeBase != null)
- location = new URL(ge.codeBase);
+ location = newURL(ge.codeBase);
else
location = null;
@@ -1607,7 +1607,7 @@ private CodeSource canonicalizeCodebase(CodeSource cs,
int separator = spec.indexOf("!/");
if (separator != -1) {
try {
- u = new URL(spec.substring(0, separator));
+ u = newURL(spec.substring(0, separator));
} catch (MalformedURLException e) {
// Fail silently. In this case, url stays what
// it was above
@@ -2223,4 +2223,9 @@ ProtectionDomainCache getPdMapping() {
}
}
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
}
diff --git a/src/java.base/share/classes/sun/security/provider/SeedGenerator.java b/src/java.base/share/classes/sun/security/provider/SeedGenerator.java
index d9eb83ff60dd2..94ffc26ab3fbb 100644
--- a/src/java.base/share/classes/sun/security/provider/SeedGenerator.java
+++ b/src/java.base/share/classes/sun/security/provider/SeedGenerator.java
@@ -504,6 +504,7 @@ static class URLSeedGenerator extends SeedGenerator {
@SuppressWarnings("removal")
private void init() throws IOException {
+ @SuppressWarnings("deprecation")
final URL device = new URL(deviceName);
try {
seedStream = java.security.AccessController.doPrivileged
diff --git a/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java b/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java
index 4ad35683aa1b1..eaef53598b7f1 100644
--- a/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java
+++ b/src/java.base/share/classes/sun/security/provider/certpath/OCSP.java
@@ -183,7 +183,8 @@ public static byte[] getOCSPBytes(List certIds, URI responderURI,
Base64.getEncoder().encodeToString(bytes), UTF_8));
if (encodedGetReq.length() <= 255) {
- url = new URL(encodedGetReq.toString());
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(encodedGetReq.toString());
con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
diff --git a/src/java.base/share/classes/sun/security/tools/KeyStoreUtil.java b/src/java.base/share/classes/sun/security/tools/KeyStoreUtil.java
index 7492c4cda93eb..cb025e7431585 100644
--- a/src/java.base/share/classes/sun/security/tools/KeyStoreUtil.java
+++ b/src/java.base/share/classes/sun/security/tools/KeyStoreUtil.java
@@ -155,7 +155,8 @@ public static char[] getPassWithModifier(String modifier, String arg,
try {
URL url;
try {
- url = new URL(arg);
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(arg);
} catch (java.net.MalformedURLException mue) {
File f = new File(arg);
if (f.exists()) {
diff --git a/src/java.base/share/classes/sun/security/tools/PathList.java b/src/java.base/share/classes/sun/security/tools/PathList.java
index ef524c4582192..79ff0e8055329 100644
--- a/src/java.base/share/classes/sun/security/tools/PathList.java
+++ b/src/java.base/share/classes/sun/security/tools/PathList.java
@@ -99,7 +99,9 @@ private static URL fileToURL(File file) {
name = name + "/";
}
try {
- return new URL("file", "", name);
+ @SuppressWarnings("deprecation")
+ var result = new URL("file", "", name);
+ return result;
} catch (MalformedURLException e) {
throw new IllegalArgumentException("file");
}
diff --git a/src/java.base/share/classes/sun/security/util/PolicyUtil.java b/src/java.base/share/classes/sun/security/util/PolicyUtil.java
index 150d2cf98efbb..dc29f97ca044e 100644
--- a/src/java.base/share/classes/sun/security/util/PolicyUtil.java
+++ b/src/java.base/share/classes/sun/security/util/PolicyUtil.java
@@ -110,14 +110,16 @@ public static InputStream getInputStream(URL url) throws IOException {
if (storePassURL != null) {
URL passURL;
try {
- passURL = new URL(storePassURL);
+ @SuppressWarnings("deprecation")
+ var _unused = passURL = new URL(storePassURL);
// absolute URL
} catch (MalformedURLException e) {
// relative URL
if (policyUrl == null) {
throw e;
}
- passURL = new URL(policyUrl, storePassURL);
+ @SuppressWarnings("deprecation")
+ var _unused = passURL = new URL(policyUrl, storePassURL);
}
if (debug != null) {
@@ -138,14 +140,16 @@ public static InputStream getInputStream(URL url) throws IOException {
*/
URL keyStoreUrl;
try {
- keyStoreUrl = new URL(keyStoreName);
+ @SuppressWarnings("deprecation")
+ var _unused = keyStoreUrl = new URL(keyStoreName);
// absolute URL
} catch (MalformedURLException e) {
// relative URL
if (policyUrl == null) {
throw e;
}
- keyStoreUrl = new URL(policyUrl, keyStoreName);
+ @SuppressWarnings("deprecation")
+ var _unused = keyStoreUrl = new URL(policyUrl, keyStoreName);
}
if (debug != null) {
diff --git a/src/java.base/unix/classes/sun/net/www/protocol/file/Handler.java b/src/java.base/unix/classes/sun/net/www/protocol/file/Handler.java
index 207e95d27f8fd..4b2c110b3e1df 100644
--- a/src/java.base/unix/classes/sun/net/www/protocol/file/Handler.java
+++ b/src/java.base/unix/classes/sun/net/www/protocol/file/Handler.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -77,7 +77,8 @@ public URLConnection openConnection(URL u, Proxy p)
URL ru;
try {
- ru = new URL("ftp", host, u.getFile() +
+ @SuppressWarnings("deprecation")
+ var _unused = ru = new URL("ftp", host, u.getFile() +
(u.getRef() == null ? "": "#" + u.getRef()));
if (p != null) {
uc = ru.openConnection(p);
diff --git a/src/java.base/unix/classes/sun/security/provider/NativePRNG.java b/src/java.base/unix/classes/sun/security/provider/NativePRNG.java
index 5bdd85c4f898c..25548bfeb8096 100644
--- a/src/java.base/unix/classes/sun/security/provider/NativePRNG.java
+++ b/src/java.base/unix/classes/sun/security/provider/NativePRNG.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -108,7 +108,8 @@ private static URL getEgdUrl() {
debug.println("NativePRNG egdUrl: " + egdSource);
}
try {
- egdUrl = new URL(egdSource);
+ @SuppressWarnings("deprecation")
+ var _unused = egdUrl = new URL(egdSource);
if (!egdUrl.getProtocol().equalsIgnoreCase("file")) {
return null;
}
diff --git a/src/java.base/windows/classes/sun/net/www/protocol/file/Handler.java b/src/java.base/windows/classes/sun/net/www/protocol/file/Handler.java
index 18ccda6e7c1d9..2865aa32a95ff 100644
--- a/src/java.base/windows/classes/sun/net/www/protocol/file/Handler.java
+++ b/src/java.base/windows/classes/sun/net/www/protocol/file/Handler.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -94,7 +94,8 @@ public URLConnection openConnection(URL url, Proxy p)
URL newurl;
try {
- newurl = new URL("ftp", host, file +
+ @SuppressWarnings("deprecation")
+ var _unused = newurl = new URL("ftp", host, file +
(url.getRef() == null ? "":
"#" + url.getRef()));
if (p != null) {
diff --git a/src/java.base/windows/classes/sun/net/www/protocol/jar/JarFileFactory.java b/src/java.base/windows/classes/sun/net/www/protocol/jar/JarFileFactory.java
index 8f8808bd5eb99..178ffe84a0643 100644
--- a/src/java.base/windows/classes/sun/net/www/protocol/jar/JarFileFactory.java
+++ b/src/java.base/windows/classes/sun/net/www/protocol/jar/JarFileFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -155,7 +155,8 @@ private URL urlFor(URL url) throws IOException {
if (host != null && !host.isEmpty() &&
!host.equalsIgnoreCase("localhost")) {
- url = new URL("file", "", "//" + host + url.getPath());
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL("file", "", "//" + host + url.getPath());
}
}
return url;
diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java
index 0a7591bd064f4..32cd2efa79564 100644
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -145,7 +145,9 @@ public Object translateBytes(byte[] bytes, DataFlavor flavor,
String xml = new String(bytes, charset);
// macosx pasteboard returns a property list that consists of one URL
// let's extract it.
- return new URL(extractURL(xml));
+ @SuppressWarnings("deprecation")
+ var result = new URL(extractURL(xml));
+ return result;
}
if(isUriListFlavor(flavor) && format == CF_FILE) {
diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
index 075e4d54f598a..d430825bb8565 100644
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
@@ -999,8 +999,10 @@ public boolean enableInputMethodsForTextComponent() {
private static URL getScaledImageURL(URL url) {
try {
String scaledImagePath = getScaledImageName(url.getPath());
- return scaledImagePath == null ? null : new URL(url.getProtocol(),
+ @SuppressWarnings("deprecation")
+ var result = scaledImagePath == null ? null : new URL(url.getProtocol(),
url.getHost(), url.getPort(), scaledImagePath);
+ return result;
} catch (MalformedURLException e) {
return null;
}
diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
index dc9838154415b..295e474579bd7 100644
--- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
+++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
@@ -157,6 +157,7 @@ protected Metacity(String themeName) throws IOException, ParserConfigurationExce
this.themeName = themeName;
themeDir = getThemeDir(themeName);
if (themeDir != null) {
+ @SuppressWarnings("deprecation")
URL themeURL = new URL(themeDir, "metacity-theme-1.xml");
xmlDoc = getXMLDoc(themeURL);
if (xmlDoc == null) {
@@ -558,7 +559,8 @@ public Object run() {
if (url != null) {
String str = url.toString();
try {
- themeDir = new URL(str.substring(0, str.lastIndexOf('/'))+"/");
+ @SuppressWarnings("deprecation")
+ var _unused = themeDir = new URL(str.substring(0, str.lastIndexOf('/'))+"/");
} catch (MalformedURLException ex) {
themeDir = null;
}
@@ -576,6 +578,7 @@ public Object run() {
}
// Note: this is a small file (< 1024 bytes) so it's not worth
// starting an XML parser or even to use a buffered reader.
+ @SuppressWarnings("deprecation")
URL url = new URL(new File(userHome).toURI().toURL(),
".gconf/apps/metacity/general/%25gconf.xml");
// Pending: verify character encoding spec for gconf
@@ -668,6 +671,7 @@ protected Image getImage(String key) {
if (image == null) {
if (themeDir != null) {
try {
+ @SuppressWarnings("deprecation")
URL url = new URL(themeDir, key);
image = (Image)new Privileged().doPrivileged(Privileged.GET_IMAGE, url);
} catch (MalformedURLException ex) {
diff --git a/src/java.desktop/share/classes/java/applet/Applet.java b/src/java.desktop/share/classes/java/applet/Applet.java
index 9f0373205d876..1d0e25e117767 100644
--- a/src/java.desktop/share/classes/java/applet/Applet.java
+++ b/src/java.desktop/share/classes/java/applet/Applet.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -313,7 +313,9 @@ public Image getImage(URL url) {
*/
public Image getImage(URL url, String name) {
try {
- return getImage(new URL(url, name));
+ @SuppressWarnings("deprecation")
+ var u = new URL(url, name);
+ return getImage(u);
} catch (MalformedURLException e) {
return null;
}
@@ -363,7 +365,9 @@ public AudioClip getAudioClip(URL url) {
*/
public AudioClip getAudioClip(URL url, String name) {
try {
- return getAudioClip(new URL(url, name));
+ @SuppressWarnings("deprecation")
+ var u = new URL(url, name);
+ return getAudioClip(u);
} catch (MalformedURLException e) {
return null;
}
diff --git a/src/java.desktop/share/classes/java/awt/SplashScreen.java b/src/java.desktop/share/classes/java/awt/SplashScreen.java
index b7318bd04a65f..a7939f4a385c5 100644
--- a/src/java.desktop/share/classes/java/awt/SplashScreen.java
+++ b/src/java.desktop/share/classes/java/awt/SplashScreen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -224,7 +224,9 @@ public URL getImageURL() throws IllegalStateException {
String jarName = _getImageJarName(splashPtr);
if (fileName != null) {
if (jarName != null) {
- imageURL = new URL("jar:"+(new File(jarName).toURL().toString())+"!/"+fileName);
+ @SuppressWarnings("deprecation")
+ var _unused = imageURL =
+ new URL("jar:"+(new File(jarName).toURL().toString())+"!/"+fileName);
} else {
imageURL = new File(fileName).toURL();
}
diff --git a/src/java.desktop/share/classes/java/beans/Beans.java b/src/java.desktop/share/classes/java/beans/Beans.java
index 131473f83bf94..6dd1aa9f39c1a 100644
--- a/src/java.desktop/share/classes/java/beans/Beans.java
+++ b/src/java.desktop/share/classes/java/beans/Beans.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,7 @@
import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
@@ -304,13 +305,13 @@ public static Object instantiate(ClassLoader cls, String beanName,
if (s.endsWith(resourceName)) {
int ix = s.length() - resourceName.length();
- codeBase = new URL(s.substring(0,ix));
+ codeBase = newURL(s.substring(0,ix));
docBase = codeBase;
ix = s.lastIndexOf('/');
if (ix >= 0) {
- docBase = new URL(s.substring(0,ix+1));
+ docBase = newURL(s.substring(0,ix+1));
}
}
}
@@ -356,6 +357,11 @@ private static void unsafeBeanContextAdd(BeanContext beanContext, Object res) {
beanContext.add(res);
}
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
+
/**
* From a given bean, obtain an object representing a specified
* type view of that source object.
diff --git a/src/java.desktop/share/classes/javax/swing/JEditorPane.java b/src/java.desktop/share/classes/javax/swing/JEditorPane.java
index 236e187fde81c..ee2f174206c0a 100644
--- a/src/java.desktop/share/classes/javax/swing/JEditorPane.java
+++ b/src/java.desktop/share/classes/javax/swing/JEditorPane.java
@@ -795,9 +795,11 @@ protected InputStream getStream(URL page) throws IOException {
if (redirect) {
String loc = conn.getHeaderField("Location");
if (loc.startsWith("http", 0)) {
- page = new URL(loc);
+ @SuppressWarnings("deprecation")
+ var _unused = page = new URL(loc);
} else {
- page = new URL(page, loc);
+ @SuppressWarnings("deprecation")
+ var _unused = page = new URL(page, loc);
}
return getStream(page);
}
@@ -926,6 +928,7 @@ public void setPage(String url) throws IOException {
if (url == null) {
throw new IOException("invalid url");
}
+ @SuppressWarnings("deprecation")
URL page = new URL(url);
setPage(page);
}
@@ -1948,7 +1951,8 @@ public Object getAccessibleActionObject(int i) {
if (href != null) {
URL u;
try {
- u = new URL(JEditorPane.this.getPage(), href);
+ @SuppressWarnings("deprecation")
+ var _unused = u = new URL(JEditorPane.this.getPage(), href);
} catch (MalformedURLException m) {
u = null;
}
diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java
index 71dda727219b8..2da1f958718b6 100644
--- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java
+++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java
@@ -260,7 +260,9 @@ private URL getResource(String path) {
return _classResourceBase.getResource(path);
} else {
try {
- return new URL(_urlResourceBase, path);
+ @SuppressWarnings("deprecation")
+ var result = new URL(_urlResourceBase, path);
+ return result;
} catch (MalformedURLException mue) {
return null;
}
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/CSS.java b/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
index 73087bd20225f..37a0c9306172b 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1293,6 +1293,7 @@ static URL getURL(URL base, String cssString) {
}
// Absolute first
try {
+ @SuppressWarnings("deprecation")
URL url = new URL(cssString);
if (url != null) {
return url;
@@ -1303,6 +1304,7 @@ static URL getURL(URL base, String cssString) {
if (base != null) {
// Relative URL, try from base
try {
+ @SuppressWarnings("deprecation")
URL url = new URL(base, cssString);
return url;
}
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/FormView.java b/src/java.desktop/share/classes/javax/swing/text/html/FormView.java
index 62ebaa5fdbe72..8af4f9e2f1e19 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/FormView.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/FormView.java
@@ -276,6 +276,7 @@ private JComponent createInputComponent(AttributeSet attr, Object model) {
JButton button;
try {
URL base = ((HTMLDocument)getElement().getDocument()).getBase();
+ @SuppressWarnings("deprecation")
URL srcURL = new URL(base, srcAtt);
Icon icon = new ImageIcon(srcURL);
button = new JButton(icon);
@@ -515,13 +516,15 @@ protected void submitData(String data) {
String action = (String) attrs.getAttribute(HTML.Attribute.ACTION);
URL actionURL;
try {
- actionURL = (action == null)
+ @SuppressWarnings("deprecation")
+ var _unused = actionURL = (action == null)
? new URL(base.getProtocol(), base.getHost(),
base.getPort(), base.getFile())
: new URL(base, action);
if (!isPostMethod) {
String query = data.toString();
- actionURL = new URL(actionURL + "?" + query);
+ @SuppressWarnings("deprecation")
+ var _unused2 = actionURL = new URL(actionURL + "?" + query);
}
} catch (MalformedURLException e) {
actionURL = null;
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/FrameView.java b/src/java.desktop/share/classes/javax/swing/text/html/FrameView.java
index 5ecbaefa70961..345f947a9cce1 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/FrameView.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/FrameView.java
@@ -71,7 +71,8 @@ protected Component createComponent() {
if (srcAtt != null && !srcAtt.isEmpty()) {
try {
URL base = ((HTMLDocument)elem.getDocument()).getBase();
- src = new URL(base, srcAtt);
+ @SuppressWarnings("deprecation")
+ var _unused = src = new URL(base, srcAtt);
htmlPane = new FrameEditorPane();
htmlPane.addHyperlinkListener(this);
JEditorPane host = getHostPane();
@@ -373,7 +374,8 @@ public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
}
Object postData = movePostData(htmlPane, null);
- src = new URL(base, srcAtt);
+ @SuppressWarnings("deprecation")
+ var _unused = src = new URL(base, srcAtt);
if (oldPage.equals(src) && (src.getRef() == null) && (postData == null)) {
return;
}
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/HTMLDocument.java b/src/java.desktop/share/classes/javax/swing/text/html/HTMLDocument.java
index c75425fd2877c..61463eb431fb3 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/HTMLDocument.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/HTMLDocument.java
@@ -3528,6 +3528,7 @@ public void start(HTML.Tag t, MutableAttributeSet attr) {
String href = (String) attr.getAttribute(HTML.Attribute.HREF);
if (href != null) {
try {
+ @SuppressWarnings("deprecation")
URL newBase = new URL(base, href);
setBase(newBase);
hasBaseTag = true;
@@ -4122,10 +4123,12 @@ void addCSSRules(String rules) {
void linkCSSStyleSheet(String href) {
URL url;
try {
- url = new URL(base, href);
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(base, href);
} catch (MalformedURLException mfe) {
try {
- url = new URL(href);
+ @SuppressWarnings("deprecation")
+ var _unused = url = new URL(href);
} catch (MalformedURLException mfe2) {
url = null;
}
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java
index 4347e96d675a3..24e8c255547c7 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java
@@ -969,7 +969,8 @@ HyperlinkEvent createHyperlinkEvent(JEditorPane html,
URL u;
try {
URL base = hdoc.getBase();
- u = new URL(base, href);
+ @SuppressWarnings("deprecation")
+ var _unused = u = new URL(base, href);
// Following is a workaround for 1.2, in which
// new URL("file://...", "#...") causes the filename to
// be lost.
@@ -979,7 +980,8 @@ HyperlinkEvent createHyperlinkEvent(JEditorPane html,
String newFile = u.getFile();
if (baseFile != null && newFile != null &&
!newFile.startsWith(baseFile)) {
- u = new URL(base, baseFile + href);
+ @SuppressWarnings("deprecation")
+ var _unused2 = u = new URL(base, baseFile + href);
}
}
} catch (MalformedURLException m) {
@@ -1013,7 +1015,8 @@ void fireEvents(JEditorPane editor, HTMLDocument doc, String href,
// fire an exited event on the old link
URL u;
try {
- u = new URL(doc.getBase(), this.href);
+ @SuppressWarnings("deprecation")
+ var _unused = u = new URL(doc.getBase(), this.href);
} catch (MalformedURLException m) {
u = null;
}
@@ -1026,7 +1029,8 @@ void fireEvents(JEditorPane editor, HTMLDocument doc, String href,
// fire an entered event on the new link
URL u;
try {
- u = new URL(doc.getBase(), href);
+ @SuppressWarnings("deprecation")
+ var _unused = u = new URL(doc.getBase(), href);
} catch (MalformedURLException m) {
u = null;
}
@@ -2392,6 +2396,7 @@ private void activateLink(String href, HTMLDocument doc,
try {
URL page =
(URL)doc.getProperty(Document.StreamDescriptionProperty);
+ @SuppressWarnings("deprecation")
URL url = new URL(page, href);
HyperlinkEvent linkEvent = new HyperlinkEvent
(editor, HyperlinkEvent.EventType.
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/ImageView.java b/src/java.desktop/share/classes/javax/swing/text/html/ImageView.java
index c48b00e56a3d4..9f7b334edbebd 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/ImageView.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/ImageView.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -196,6 +196,7 @@ public URL getImageURL() {
URL reference = ((HTMLDocument)getDocument()).getBase();
try {
+ @SuppressWarnings("deprecation")
URL u = new URL(reference,src);
return u;
} catch (MalformedURLException e) {
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/IsindexView.java b/src/java.desktop/share/classes/javax/swing/text/html/IsindexView.java
index 4b2fb1e1c7369..22c345027ae9f 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/IsindexView.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/IsindexView.java
@@ -104,6 +104,7 @@ public void actionPerformed(ActionEvent evt) {
action = hdoc.getBase().toString();
}
try {
+ @SuppressWarnings("deprecation")
URL url = new URL(action+"?"+data);
JEditorPane pane = (JEditorPane)getContainer();
pane.setPage(url);
diff --git a/src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java b/src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java
index a10988c19b3d2..fd3c75829e861 100644
--- a/src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java
+++ b/src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java
@@ -2105,11 +2105,13 @@ public static final class ListPainter implements Serializable {
tmpstr = st.nextToken();
if (st.hasMoreTokens())
tmpstr = st.nextToken();
+ @SuppressWarnings("deprecation")
URL u = new URL(tmpstr);
img = new ImageIcon(u);
} catch (MalformedURLException e) {
if (tmpstr != null && ss != null && ss.getBase() != null) {
try {
+ @SuppressWarnings("deprecation")
URL u = new URL(ss.getBase(), tmpstr);
img = new ImageIcon(u);
} catch (MalformedURLException murle) {
diff --git a/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java b/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java
index 379b3e46cf592..0cb44ae64b0bc 100644
--- a/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java
+++ b/src/java.desktop/share/classes/sun/awt/image/URLImageSource.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -58,7 +58,7 @@ public URLImageSource(URL u) {
}
public URLImageSource(String href) throws MalformedURLException {
- this(new URL(null, href));
+ this(newURL(null, href));
}
public URLImageSource(URL u, URLConnection uc) {
@@ -159,4 +159,9 @@ protected ImageDecoder getDecoder() {
}
return id;
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(URL context, String spec) throws MalformedURLException {
+ return new URL(context, spec);
+ }
}
diff --git a/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java b/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java
index 0e398edef8575..e2a69c79c3e11 100644
--- a/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java
+++ b/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -291,6 +291,7 @@ static String[] getDefaultPrinter() {
return printerInfo.clone();
}
try {
+ @SuppressWarnings("deprecation")
URL url = new URL("http", getServer(), getPort(), "");
final HttpURLConnection urlConnection =
IPPPrintService.getIPPConnection(url);
@@ -405,6 +406,7 @@ static String[] getAllPrinters() {
}
try {
+ @SuppressWarnings("deprecation")
URL url = new URL("http", getServer(), getPort(), "");
final HttpURLConnection urlConnection =
diff --git a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java
index 82cb84a14550e..91be3e06a5a7a 100644
--- a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java
+++ b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -36,6 +36,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -406,7 +407,7 @@ protected static void debug_println(String str) {
defaultMediaIndex = -1;
try {
myURL =
- new URL(uriStr.replaceFirst("ipp", "http"));
+ newURL(uriStr.replaceFirst("ipp", "http"));
} catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+
" IPPPrintService, myURL="+
@@ -1762,7 +1763,7 @@ public synchronized boolean isPostscript() {
if (isCupsPrinter) {
try {
urlConnection = getIPPConnection(
- new URL(myURL+".ppd"));
+ newURL(myURL+".ppd"));
InputStream is = urlConnection.getInputStream();
if (is != null) {
@@ -2076,4 +2077,9 @@ public boolean equals(Object obj) {
public int hashCode() {
return this.getClass().hashCode()+getName().hashCode();
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
}
diff --git a/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java b/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java
index 7fa1b201340c5..75e77e23a121e 100644
--- a/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java
+++ b/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
import java.io.BufferedReader;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Vector;
@@ -475,7 +476,7 @@ private PrintService getServiceByName(PrinterName nameAttr) {
if (CUPSPrinter.isCupsRunning()) {
try {
return new IPPPrintService(name,
- new URL("http://"+
+ newURL("http://"+
CUPSPrinter.getServer()+":"+
CUPSPrinter.getPort()+"/"+
name));
@@ -687,7 +688,7 @@ public synchronized PrintService getDefaultPrintService() {
psuri, true);
} else {
defaultPS = new IPPPrintService(defaultPrinter,
- new URL("http://"+
+ newURL("http://"+
CUPSPrinter.getServer()+":"+
CUPSPrinter.getPort()+"/"+
defaultPrinter));
@@ -969,4 +970,9 @@ public void run() {
}
}
}
+
+ @SuppressWarnings("deprecation")
+ private static URL newURL(String spec) throws MalformedURLException {
+ return new URL(spec);
+ }
}
diff --git a/src/java.desktop/windows/classes/sun/awt/windows/WDataTransferer.java b/src/java.desktop/windows/classes/sun/awt/windows/WDataTransferer.java
index 456300c6197c5..d665047c795db 100644
--- a/src/java.desktop/windows/classes/sun/awt/windows/WDataTransferer.java
+++ b/src/java.desktop/windows/classes/sun/awt/windows/WDataTransferer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -271,7 +271,9 @@ public Object translateBytes(byte[] bytes, DataFlavor flavor, long format,
} catch (UnsupportedFlavorException cannotHappen) {
}
}
- return new URL(new String(bytes, charset));
+ @SuppressWarnings("deprecation")
+ var result = new URL(new String(bytes, charset));
+ return result;
}
return super.translateBytes(bytes , flavor, format,
diff --git a/src/java.management/share/classes/javax/management/loading/MLet.java b/src/java.management/share/classes/javax/management/loading/MLet.java
index ec6ab22e09634..250e5945645ce 100644
--- a/src/java.management/share/classes/javax/management/loading/MLet.java
+++ b/src/java.management/share/classes/javax/management/loading/MLet.java
@@ -406,6 +406,7 @@ public void addURL(URL url) {
*/
public void addURL(String url) throws ServiceNotFoundException {
try {
+ @SuppressWarnings("deprecation")
URL ur = new URL(url);
if (!Arrays.asList(getURLs()).contains(ur))
super.addURL(ur);
@@ -571,8 +572,10 @@ public Set