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
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue