mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8294241: Deprecate URL public constructors
Reviewed-by: joehw, prr, alanb, aefimov, michaelm
This commit is contained in:
parent
68209adfa7
commit
4338f527aa
82 changed files with 848 additions and 146 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue