8294241: Deprecate URL public constructors

Reviewed-by: joehw, prr, alanb, aefimov, michaelm
This commit is contained in:
Daniel Fuchs 2022-11-03 17:18:14 +00:00
parent 68209adfa7
commit 4338f527aa
82 changed files with 848 additions and 146 deletions

View file

@ -694,7 +694,9 @@ public class File
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;
}
/**

View file

@ -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 @@ import java.util.Set;
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);

View file

@ -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 @@ public abstract class JarURLConnection extends URLConnection {
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;

View file

@ -1133,7 +1133,7 @@ public final class 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 --

View file

@ -129,6 +129,26 @@ import sun.security.action.GetPropertyAction;
* 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.
*
* <h2><a id="constructor-deprecation"></a>Constructing instances of {@code URL}</h2>
*
* 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.
* <p>
* 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.
* <p>
* 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 @@ import sun.security.action.GetPropertyAction;
*
* @apiNote
*
* <a id="integrity"></a>
* 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 @@ import sun.security.action.GetPropertyAction;
* from the direct string representation of a {@code File} or {@code Path}
* instance.
* <p>
* 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}.
* <p>
* Some components of a URL or URI, such as <i>userinfo</i>, 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
* <a href="#constructor-deprecation">constructor deprecation</a> for more
* details.
*/
@Deprecated(since = "20")
public URL(String protocol, String host, int port, String file)
throws MalformedURLException
{
@ -399,7 +429,11 @@ public final class URL implements java.io.Serializable {
* 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
* <a href="#constructor-deprecation">constructor deprecation</a> 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 final class URL implements java.io.Serializable {
* 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 <a href="#constructor-deprecation">constructor deprecation</a>
* 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 final class URL implements java.io.Serializable {
* 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
* <a href="#constructor-deprecation">constructor deprecation</a> for more
* details.
*/
@Deprecated(since = "20")
public URL(String spec) throws MalformedURLException {
this(null, spec);
}
@ -593,7 +637,11 @@ public final class URL implements java.io.Serializable {
* @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
* <a href="#constructor-deprecation">constructor deprecation</a> for more
* details.
*/
@Deprecated(since = "20")
public URL(URL context, String spec) throws MalformedURLException {
this(context, spec, null);
}
@ -626,7 +674,13 @@ public final class URL implements java.io.Serializable {
* @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 <a href="#constructor-deprecation">constructor deprecation</a>
* for more details.
*/
@Deprecated(since = "20")
public URL(URL context, String spec, URLStreamHandler handler)
throws MalformedURLException
{
@ -748,23 +802,70 @@ public final class URL implements java.io.Serializable {
}
/**
* 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 <a href=#integrity>API note</a> 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 @@ public final class URL implements java.io.Serializable {
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);
}
/*

View file

@ -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 @@ public final class Security {
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 final class Security {
}
return Collections.unmodifiableSet(result);
}
@SuppressWarnings("deprecation")
private static URL newURL(String spec) throws MalformedURLException {
return new URL(spec);
}
}

View file

@ -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);
}

View file

@ -91,6 +91,7 @@ final class ProviderVerifier {
// 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 + "!/");

View file

@ -493,6 +493,7 @@ public class URLClassPath {
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 @@ public class URLClassPath {
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 @@ public class URLClassPath {
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 @@ public class URLClassPath {
@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 @@ public class URLClassPath {
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 class URLClassPath {
// 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 @@ public class URLClassPath {
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 @@ public class URLClassPath {
} 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 @@ public class URLClassPath {
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 @@ public class URLClassPath {
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 @@ public class URLClassPath {
* @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 @@ public class URLClassPath {
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 @@ public class URLClassPath {
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 @@ public class URLClassPath {
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

View file

@ -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 final class ModulePatcher {
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;
}

View file

@ -95,6 +95,7 @@ public class URLUtil {
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

View file

@ -239,7 +239,9 @@ public final class ParseUtil {
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) {

View file

@ -987,7 +987,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
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 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
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 class HttpURLConnection extends java.net.HttpURLConnection {
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 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
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 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
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 class HttpURLConnection extends java.net.HttpURLConnection {
}
}
}
@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

View file

@ -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 @@ public class Handler extends java.net.URLStreamHandler {
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 @@ public class Handler extends java.net.URLStreamHandler {
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 @@ public class Handler extends java.net.URLStreamHandler {
// 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 @@ public class Handler extends java.net.URLStreamHandler {
return file;
}
@SuppressWarnings("deprecation")
private static URL newURL(String spec) throws MalformedURLException {
return new URL(spec);
}
}

View file

@ -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 class JavaRuntimeURLConnection extends URLConnection {
/**
* 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 @@ public class JavaRuntimeURLConnection extends URLConnection {
/**
* Returns a jrt URL for the given module.
*/
@SuppressWarnings("deprecation")
private static URL toJrtURL(String module) {
try {
return new URL("jrt:/" + module);

View file

@ -256,7 +256,7 @@ public final class ConfigFile extends Configuration {
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 @@ public final class ConfigFile extends Configuration {
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 @@ public final class ConfigFile extends Configuration {
return new IOException(form.format(args));
}
}
@SuppressWarnings("deprecation")
private static URL newURL(String spec) throws MalformedURLException {
return new URL(spec);
}
}

View file

@ -414,7 +414,7 @@ public class PolicyFile extends java.security.Policy {
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 @@ public class PolicyFile extends java.security.Policy {
URL location;
if (ge.codeBase != null)
location = new URL(ge.codeBase);
location = newURL(ge.codeBase);
else
location = null;
@ -1607,7 +1607,7 @@ public class PolicyFile extends java.security.Policy {
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 @@ public class PolicyFile extends java.security.Policy {
}
}
}
@SuppressWarnings("deprecation")
private static URL newURL(String spec) throws MalformedURLException {
return new URL(spec);
}
}

View file

@ -504,6 +504,7 @@ abstract class SeedGenerator {
@SuppressWarnings("removal")
private void init() throws IOException {
@SuppressWarnings("deprecation")
final URL device = new URL(deviceName);
try {
seedStream = java.security.AccessController.doPrivileged

View file

@ -183,7 +183,8 @@ public final class OCSP {
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);

View file

@ -155,7 +155,8 @@ public class KeyStoreUtil {
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()) {

View file

@ -99,7 +99,9 @@ public class PathList {
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");
}

View file

@ -110,14 +110,16 @@ public class PolicyUtil {
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 class PolicyUtil {
*/
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) {