8294241: Deprecate URL public constructors
Reviewed-by: joehw, prr, alanb, aefimov, michaelm
This commit is contained in:
parent
68209adfa7
commit
4338f527aa
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 --
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 + "!/");
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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 class Handler extends URLStreamHandler {
|
||||
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);
|
||||
|
@ -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 @@ public final class NativePRNG extends SecureRandomSpi {
|
||||
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;
|
||||
}
|
||||
|
@ -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 class Handler extends URLStreamHandler {
|
||||
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) {
|
||||
|
@ -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 @@ class JarFileFactory implements URLJarFile.URLJarFileCloseController {
|
||||
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;
|
||||
|
@ -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 class CDataTransferer extends DataTransferer {
|
||||
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) {
|
||||
|
@ -999,8 +999,10 @@ public final class LWCToolkit extends LWToolkit {
|
||||
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;
|
||||
}
|
||||
|
@ -157,6 +157,7 @@ class Metacity implements SynthConstants {
|
||||
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 @@ class Metacity implements SynthConstants {
|
||||
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 @@ class Metacity implements SynthConstants {
|
||||
}
|
||||
// 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 @@ class Metacity implements SynthConstants {
|
||||
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) {
|
||||
|
@ -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 class Applet extends Panel {
|
||||
*/
|
||||
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 class Applet extends Panel {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
@ -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 final class SplashScreen {
|
||||
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();
|
||||
}
|
||||
|
@ -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.io.StreamCorruptedException;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Enumeration;
|
||||
@ -304,13 +305,13 @@ public class Beans {
|
||||
|
||||
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 @@ public class Beans {
|
||||
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.
|
||||
|
@ -795,9 +795,11 @@ public class JEditorPane extends JTextComponent {
|
||||
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 class JEditorPane extends JTextComponent {
|
||||
if (url == null) {
|
||||
throw new IOException("invalid url");
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
URL page = new URL(url);
|
||||
setPage(page);
|
||||
}
|
||||
@ -1948,7 +1951,8 @@ public class JEditorPane extends JTextComponent {
|
||||
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;
|
||||
}
|
||||
|
@ -260,7 +260,9 @@ class SynthParser extends DefaultHandler {
|
||||
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;
|
||||
}
|
||||
|
@ -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 @@ public class CSS implements Serializable {
|
||||
}
|
||||
// Absolute first
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(cssString);
|
||||
if (url != null) {
|
||||
return url;
|
||||
@ -1303,6 +1304,7 @@ public class CSS implements Serializable {
|
||||
if (base != null) {
|
||||
// Relative URL, try from base
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(base, cssString);
|
||||
return url;
|
||||
}
|
||||
|
@ -276,6 +276,7 @@ public class FormView extends ComponentView implements ActionListener {
|
||||
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 @@ public class FormView extends ComponentView implements ActionListener {
|
||||
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;
|
||||
|
@ -71,7 +71,8 @@ class FrameView extends ComponentView implements HyperlinkListener {
|
||||
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 @@ class FrameView extends ComponentView implements HyperlinkListener {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -3528,6 +3528,7 @@ public class HTMLDocument extends DefaultStyledDocument {
|
||||
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 @@ public class HTMLDocument extends DefaultStyledDocument {
|
||||
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;
|
||||
}
|
||||
|
@ -969,7 +969,8 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
|
||||
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 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
|
||||
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 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
|
||||
// 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 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
|
||||
// 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 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
|
||||
try {
|
||||
URL page =
|
||||
(URL)doc.getProperty(Document.StreamDescriptionProperty);
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(page, href);
|
||||
HyperlinkEvent linkEvent = new HyperlinkEvent
|
||||
(editor, HyperlinkEvent.EventType.
|
||||
|
@ -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 class ImageView extends View {
|
||||
|
||||
URL reference = ((HTMLDocument)getDocument()).getBase();
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL u = new URL(reference,src);
|
||||
return u;
|
||||
} catch (MalformedURLException e) {
|
||||
|
@ -104,6 +104,7 @@ class IsindexView extends ComponentView implements ActionListener {
|
||||
action = hdoc.getBase().toString();
|
||||
}
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(action+"?"+data);
|
||||
JEditorPane pane = (JEditorPane)getContainer();
|
||||
pane.setPage(url);
|
||||
|
@ -2105,11 +2105,13 @@ public class StyleSheet extends StyleContext {
|
||||
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) {
|
||||
|
@ -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 class URLImageSource extends InputStreamImageSource {
|
||||
}
|
||||
|
||||
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 @@ public class URLImageSource extends InputStreamImageSource {
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static URL newURL(URL context, String spec) throws MalformedURLException {
|
||||
return new URL(context, spec);
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ public class CUPSPrinter {
|
||||
return printerInfo.clone();
|
||||
}
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL("http", getServer(), getPort(), "");
|
||||
final HttpURLConnection urlConnection =
|
||||
IPPPrintService.getIPPConnection(url);
|
||||
@ -405,6 +406,7 @@ public class CUPSPrinter {
|
||||
}
|
||||
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL("http", getServer(), getPort(), "");
|
||||
|
||||
final HttpURLConnection urlConnection =
|
||||
|
@ -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.InputStreamReader;
|
||||
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 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
|
||||
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 class IPPPrintService implements PrintService, SunPrinterJobService {
|
||||
if (isCupsPrinter) {
|
||||
try {
|
||||
urlConnection = getIPPConnection(
|
||||
new URL(myURL+".ppd"));
|
||||
newURL(myURL+".ppd"));
|
||||
|
||||
InputStream is = urlConnection.getInputStream();
|
||||
if (is != null) {
|
||||
@ -2076,4 +2077,9 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
|
||||
public int hashCode() {
|
||||
return this.getClass().hashCode()+getName().hashCode();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static URL newURL(String spec) throws MalformedURLException {
|
||||
return new URL(spec);
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ package sun.print;
|
||||
|
||||
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 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
|
||||
if (CUPSPrinter.isCupsRunning()) {
|
||||
try {
|
||||
return new IPPPrintService(name,
|
||||
new URL("http://"+
|
||||
newURL("http://"+
|
||||
CUPSPrinter.getServer()+":"+
|
||||
CUPSPrinter.getPort()+"/"+
|
||||
name));
|
||||
@ -687,7 +688,7 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
|
||||
psuri, true);
|
||||
} else {
|
||||
defaultPS = new IPPPrintService(defaultPrinter,
|
||||
new URL("http://"+
|
||||
newURL("http://"+
|
||||
CUPSPrinter.getServer()+":"+
|
||||
CUPSPrinter.getPort()+"/"+
|
||||
defaultPrinter));
|
||||
@ -969,4 +970,9 @@ public class PrintServiceLookupProvider extends PrintServiceLookup
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static URL newURL(String spec) throws MalformedURLException {
|
||||
return new URL(spec);
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ final class WDataTransferer extends DataTransferer {
|
||||
} 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,
|
||||
|
@ -406,6 +406,7 @@ public class MLet extends java.net.URLClassLoader
|
||||
*/
|
||||
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 class MLet extends java.net.URLClassLoader
|
||||
// Appends the specified JAR file URL to the list of
|
||||
// URLs to search for classes and resources.
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
var u = new URL(codebase.toString() + tok);
|
||||
if (!Arrays.asList(getURLs())
|
||||
.contains(new URL(codebase.toString() + tok))) {
|
||||
.contains(u)) {
|
||||
addURL(codebase + tok);
|
||||
}
|
||||
} catch (MalformedURLException me) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2006, 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
|
||||
@ -102,7 +102,8 @@ public class MLetContent {
|
||||
att += "/";
|
||||
}
|
||||
try {
|
||||
baseURL = new URL(documentURL, att);
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = baseURL = new URL(documentURL, att);
|
||||
} catch (MalformedURLException e) {
|
||||
// OK : Move to next block as baseURL could not be initialized.
|
||||
}
|
||||
@ -112,7 +113,8 @@ public class MLetContent {
|
||||
int i = file.lastIndexOf('/');
|
||||
if (i >= 0 && i < file.length() - 1) {
|
||||
try {
|
||||
baseURL = new URL(documentURL, file.substring(0, i + 1));
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = baseURL = new URL(documentURL, file.substring(0, i + 1));
|
||||
} catch (MalformedURLException e) {
|
||||
// OK : Move to next block as baseURL could not be initialized.
|
||||
}
|
||||
|
@ -249,6 +249,7 @@ class MLetParser {
|
||||
/**
|
||||
* Parse the document pointed by the URL urlname
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public List<MLetContent> parseURL(String urlname) throws IOException {
|
||||
// Parse the document
|
||||
//
|
||||
|
@ -126,6 +126,7 @@ public final class VersionHelper {
|
||||
return AccessController.doPrivileged(act);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static URL[] getUrlArray(String[] url) throws MalformedURLException {
|
||||
URL[] urlArray = new URL[url.length];
|
||||
for (int i = 0; i < urlArray.length; i++) {
|
||||
|
@ -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
|
||||
@ -285,7 +285,9 @@ public final class VersionHelper {
|
||||
StringTokenizer parser = new StringTokenizer(codebase);
|
||||
List<URL> list = new ArrayList<>();
|
||||
while (parser.hasMoreTokens()) {
|
||||
list.add(new URL(parser.nextToken()));
|
||||
@SuppressWarnings("deprecation")
|
||||
var u = new URL(parser.nextToken());
|
||||
list.add(u);
|
||||
}
|
||||
return list.toArray(new URL[0]);
|
||||
}
|
||||
|
@ -773,7 +773,9 @@ public final class LoaderHandler {
|
||||
StringTokenizer st = new StringTokenizer(path); // divide by spaces
|
||||
URL[] urls = new URL[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
urls[i] = new URL(st.nextToken());
|
||||
@SuppressWarnings("deprecation")
|
||||
var url = new URL(st.nextToken());
|
||||
urls[i] = url;
|
||||
}
|
||||
synchronized (pathToURLsCache) {
|
||||
pathToURLsCache.put(path,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2018, 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
|
||||
@ -540,7 +540,9 @@ public class Main {
|
||||
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");
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2019, 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
|
||||
@ -97,6 +97,7 @@ public class SerialDatalink implements Serializable, Cloneable {
|
||||
* <code>URL</code> object in the Java programming language.
|
||||
* @throws SerialException if the <code>URL</code> object cannot be de-serialized
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public URL getDatalink() throws SerialException {
|
||||
|
||||
URL aURL = null;
|
||||
|
@ -194,6 +194,7 @@ public final class DocumentCache implements DOMCache {
|
||||
*/
|
||||
private final long getLastModified(String uri) {
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(uri);
|
||||
URLConnection connection = url.openConnection();
|
||||
long timestamp = connection.getLastModified();
|
||||
|
@ -1605,7 +1605,8 @@ public class TransformerFactoryImpl
|
||||
else {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(systemId);
|
||||
@SuppressWarnings("deprecation")
|
||||
URL _unused = url = new URL(systemId);
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
return null;
|
||||
|
@ -521,7 +521,8 @@ public final class TransformerImpl extends Transformer
|
||||
}
|
||||
}
|
||||
else if (systemId.startsWith("http:")) {
|
||||
url = new URL(systemId);
|
||||
@SuppressWarnings("deprecation")
|
||||
URL _unused = url = new URL(systemId);
|
||||
final URLConnection connection = url.openConnection();
|
||||
_tohFactory.setOutputStream(_ostream = connection.getOutputStream());
|
||||
return _tohFactory.getSerializationHandler();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -647,6 +647,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
|
||||
if (reader == null) {
|
||||
stream = xmlInputSource.getByteStream();
|
||||
if (stream == null) {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL location = new URL(expandedSystemId);
|
||||
URLConnection connect = location.openConnection();
|
||||
if (!(connect instanceof HttpURLConnection)) {
|
||||
@ -2037,6 +2038,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
|
||||
public static OutputStream createOutputStream(String uri) throws IOException {
|
||||
// URI was specified. Handle relative URIs.
|
||||
final String expanded = XMLEntityManager.expandSystemId(uri, null, true);
|
||||
@SuppressWarnings("deprecation")
|
||||
final URL url = new URL(expanded != null ? expanded : uri);
|
||||
OutputStream out = null;
|
||||
String protocol = url.getProtocol();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -125,6 +125,7 @@ public class XIncludeTextReader {
|
||||
else {
|
||||
String expandedSystemId = XMLEntityManager.expandSystemId(source.getSystemId(), source.getBaseSystemId(), false);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(expandedSystemId);
|
||||
URLConnection urlCon = url.openConnection();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -220,6 +220,7 @@ final class CharInfo
|
||||
|
||||
if (is == null) {
|
||||
try {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(entitiesResource);
|
||||
is = url.openStream();
|
||||
} catch (Exception e) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
@ -335,6 +335,7 @@ public final class Encodings extends Object
|
||||
}
|
||||
|
||||
if (urlString != null && urlString.length() > 0) {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(urlString);
|
||||
is = url.openStream();
|
||||
}
|
||||
|
@ -956,6 +956,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
|
||||
// Expand the System Id and obtain an absolute URI for it.
|
||||
String absoluteURI = SystemIDResolver.getAbsoluteURI(uri);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(absoluteURI);
|
||||
OutputStream urlOutStream = null;
|
||||
String protocol = url.getProtocol();
|
||||
@ -1234,6 +1235,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
|
||||
// REVISIT: Can this be used to get an absolute expanded URI
|
||||
String absoluteURI = SystemIDResolver.getAbsoluteURI(uri);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(absoluteURI);
|
||||
OutputStream urlOutStream = null;
|
||||
String protocol = url.getProtocol();
|
||||
|
@ -25,6 +25,7 @@ import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
@ -413,7 +414,7 @@ public class ListingErrorHandler implements ErrorHandler, ErrorListener
|
||||
try
|
||||
{
|
||||
// Try to get a URL from it as-is
|
||||
url = new URL(sourceUrl);
|
||||
url = newURL(sourceUrl);
|
||||
}
|
||||
catch (java.net.MalformedURLException mue)
|
||||
{
|
||||
@ -431,7 +432,7 @@ public class ListingErrorHandler implements ErrorHandler, ErrorListener
|
||||
else
|
||||
{
|
||||
// The url is relative, so attempt to get absolute
|
||||
url = new URL(SystemIDResolver.getAbsoluteURI(sourceUrl));
|
||||
url = newURL(SystemIDResolver.getAbsoluteURI(sourceUrl));
|
||||
// If this fails, allow the exception to propagate
|
||||
}
|
||||
}
|
||||
@ -562,4 +563,8 @@ public class ListingErrorHandler implements ErrorHandler, ErrorListener
|
||||
/** If we should throw exception on fatalErrors; default:true. */
|
||||
protected boolean throwOnFatalError = true;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static URL newURL(String spec) throws MalformedURLException {
|
||||
return new URL(spec);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2017, 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
|
||||
@ -223,9 +223,11 @@ abstract class BaseEntry {
|
||||
|
||||
try {
|
||||
if (base != null) {
|
||||
url = new URL(base, uri);
|
||||
@SuppressWarnings("deprecation")
|
||||
URL _unused = url = new URL(base, uri);
|
||||
} else {
|
||||
url = new URL(uri);
|
||||
@SuppressWarnings("deprecation")
|
||||
URL _unused = url = new URL(uri);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
CatalogMessages.reportIAE(ERR_INVALID_ARGUMENT,
|
||||
|
@ -140,7 +140,8 @@ class CatalogImpl extends GroupEntry implements Catalog {
|
||||
if (verifyCatalogFile(null, uri)) {
|
||||
systemId = temp;
|
||||
try {
|
||||
baseURI = new URL(systemId);
|
||||
@SuppressWarnings("deprecation")
|
||||
URL _unused = baseURI = new URL(systemId);
|
||||
} catch (MalformedURLException e) {
|
||||
CatalogMessages.reportRunTimeError(CatalogMessages.ERR_INVALID_PATH,
|
||||
new Object[]{temp}, e);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2017, 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
|
||||
@ -154,14 +154,15 @@ final class CatalogResolverImpl implements CatalogResolver {
|
||||
new Object[]{href, base});
|
||||
}
|
||||
try {
|
||||
URL url = null;
|
||||
|
||||
if (base == null) {
|
||||
url = new URL(uri);
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(uri);
|
||||
result = url.toString();
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL baseURL = new URL(base);
|
||||
url = (href.length() == 0 ? baseURL : new URL(baseURL, uri));
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = (href.length() == 0 ? baseURL : new URL(baseURL, uri));
|
||||
result = url.toString();
|
||||
}
|
||||
} catch (java.net.MalformedURLException mue) {
|
||||
@ -219,7 +220,9 @@ final class CatalogResolverImpl implements CatalogResolver {
|
||||
if (is != null && !is.isEmpty()) {
|
||||
|
||||
try {
|
||||
return new URL(is.getSystemId()).openStream();
|
||||
@SuppressWarnings("deprecation")
|
||||
InputStream result = new URL(is.getSystemId()).openStream();
|
||||
return result;
|
||||
} catch (IOException ex) {
|
||||
//considered as no mapping.
|
||||
}
|
||||
|
@ -340,6 +340,7 @@ public class SecuritySupport {
|
||||
if (!systemId.contains(":")) {
|
||||
protocol = "file";
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL(systemId);
|
||||
protocol = url.getProtocol();
|
||||
if (protocol.equalsIgnoreCase("jar")) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 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
|
||||
@ -137,6 +137,7 @@ public class FSInfo {
|
||||
* @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())) {
|
||||
// 'input' contains a ':', which might be a scheme, or might be
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
@ -690,7 +690,9 @@ public class Main {
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL(PROTOCOL, null, -1, name, handler);
|
||||
@SuppressWarnings("deprecation")
|
||||
var result = new URL(PROTOCOL, null, -1, name, handler);
|
||||
return result;
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2006, 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
|
||||
@ -138,6 +138,7 @@ class ServiceProxy {
|
||||
for (URL url: urls) {
|
||||
try {
|
||||
String fullName = prefix + service.getName();
|
||||
@SuppressWarnings("deprecation")
|
||||
URL u = new URL(url, fullName);
|
||||
boolean found = parse(service, u);
|
||||
if (found)
|
||||
|
@ -2253,7 +2253,8 @@ public class Main {
|
||||
keyStoreName = keyStoreName.replace(File.separatorChar, '/');
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(keyStoreName);
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = url = new URL(keyStoreName);
|
||||
} catch (java.net.MalformedURLException e) {
|
||||
// try as file
|
||||
url = new File(keyStoreName).toURI().toURL();
|
||||
|
@ -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
|
||||
@ -458,7 +458,8 @@ public class HtmlOptions extends BaseOptions {
|
||||
public boolean process(String opt, List<String> args) {
|
||||
docrootParent = args.get(0);
|
||||
try {
|
||||
new URL(docrootParent);
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = new URL(docrootParent);
|
||||
} catch (MalformedURLException e) {
|
||||
messages.error("doclet.MalformedURL", docrootParent);
|
||||
return false;
|
||||
|
@ -578,7 +578,8 @@ public class Extern {
|
||||
|
||||
public boolean isUrl (String urlCandidate) {
|
||||
try {
|
||||
new URL(urlCandidate);
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = new URL(urlCandidate);
|
||||
//No exception was thrown, so this must really be a URL.
|
||||
return true;
|
||||
} catch (MalformedURLException e) {
|
||||
@ -587,6 +588,7 @@ public class Extern {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private URL toURL(String url) throws Fault {
|
||||
try {
|
||||
return new URL(url);
|
||||
@ -632,7 +634,8 @@ public class Extern {
|
||||
String loc = http.getHeaderField("Location");
|
||||
URL target = null;
|
||||
if (loc != null) {
|
||||
target = new URL(base, loc);
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = target = new URL(base, loc);
|
||||
}
|
||||
http.disconnect();
|
||||
if (target == null || redirects >= 5) {
|
||||
|
@ -1047,7 +1047,9 @@ public class JConsole extends JFrame
|
||||
if (!file.isFile()) {
|
||||
name = name + "/";
|
||||
}
|
||||
return new URL("file", "", name);
|
||||
@SuppressWarnings("deprecation")
|
||||
var result = new URL("file", "", name);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2020, 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
|
||||
@ -3077,7 +3077,8 @@ public class JShellTool implements MessageHandler {
|
||||
path = toPathResolvingUserHome(filename);
|
||||
} catch (InvalidPathException ipe) {
|
||||
try {
|
||||
url = new URL(filename);
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = url = new URL(filename);
|
||||
if (url.getProtocol().equalsIgnoreCase("file")) {
|
||||
path = Paths.get(url.toURI());
|
||||
}
|
||||
@ -3092,7 +3093,8 @@ public class JShellTool implements MessageHandler {
|
||||
} else {
|
||||
if (url == null) {
|
||||
try {
|
||||
url = new URL(filename);
|
||||
@SuppressWarnings("deprecation")
|
||||
var _unused = url = new URL(filename);
|
||||
} catch (MalformedURLException mue) {
|
||||
throw new FileNotFoundException(filename);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 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
|
||||
@ -185,9 +185,8 @@ class DefaultLoaderDelegate implements LoaderDelegate {
|
||||
private URL doFindResource(String name) {
|
||||
if (classFiles.containsKey(name)) {
|
||||
try {
|
||||
return new URL(null,
|
||||
new URI("jshell", null, "/" + name, null).toString(),
|
||||
new ResourceURLStreamHandler(name));
|
||||
return URL.of(new URI("jshell", null, "/" + name, null),
|
||||
new ResourceURLStreamHandler(name));
|
||||
} catch (MalformedURLException | URISyntaxException ex) {
|
||||
throw new InternalError(ex);
|
||||
}
|
||||
|
@ -393,7 +393,7 @@ public class KeyStoreLoginModule implements LoginModule {
|
||||
}
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new URL(keyStorePasswordURL).openStream();
|
||||
in = newURL(keyStorePasswordURL).openStream();
|
||||
keyStorePassword = Password.readPassword(in);
|
||||
} catch (IOException e) {
|
||||
LoginException le = new LoginException
|
||||
@ -421,7 +421,7 @@ public class KeyStoreLoginModule implements LoginModule {
|
||||
} else {
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new URL(privateKeyPasswordURL).openStream();
|
||||
in = newURL(privateKeyPasswordURL).openStream();
|
||||
privateKeyPassword = Password.readPassword(in);
|
||||
} catch (IOException e) {
|
||||
LoginException le = new LoginException
|
||||
@ -599,7 +599,7 @@ public class KeyStoreLoginModule implements LoginModule {
|
||||
// if using protected auth path, keyStorePassword will be null
|
||||
keyStore.load(null, keyStorePassword);
|
||||
} else {
|
||||
in = new URL(keyStoreURL).openStream();
|
||||
in = newURL(keyStoreURL).openStream();
|
||||
keyStore.load(in, keyStorePassword);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
@ -911,4 +911,9 @@ public class KeyStoreLoginModule implements LoginModule {
|
||||
System.err.println("Debug KeyStoreLoginModule: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static URL newURL(String spec) throws MalformedURLException {
|
||||
return new URL(spec);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 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
|
||||
@ -83,6 +83,11 @@ public class URIToURLTest {
|
||||
boolean userInfoCheck = userInfo == null?
|
||||
url.getUserInfo() == null :
|
||||
userInfo.equals(url.getUserInfo());
|
||||
if (!userInfoCheck) {
|
||||
throw new RuntimeException("uri.userInfo is " + userInfo +
|
||||
" url.userInfo is " +
|
||||
url.getUserInfo());
|
||||
}
|
||||
if (uri.getPort() != url.getPort())
|
||||
throw new RuntimeException("uri.port is " +
|
||||
uri.getPort() + " url's is " +
|
||||
|
377
test/jdk/java/net/URL/URLFromURITest.java
Normal file
377
test/jdk/java/net/URL/URLFromURITest.java
Normal file
@ -0,0 +1,377 @@
|
||||
/*
|
||||
* Copyright (c) 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 8294241
|
||||
* @library /test/lib
|
||||
* @modules java.base/java.net:+open
|
||||
* @summary Test URL::fromURI(URI, URLStreamHandler)
|
||||
* @run junit/othervm URLFromURITest
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodHandles.Lookup;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
import jdk.test.lib.RandomFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class URLFromURITest {
|
||||
|
||||
static final Random RAND = RandomFactory.getRandom();
|
||||
|
||||
record TestInput(String uri, URLStreamHandler handler) {
|
||||
static TestInput withNoHandler(String uri) {
|
||||
return new TestInput(uri, null);
|
||||
}
|
||||
TestInput withCustomHandler() {
|
||||
return new TestInput(uri(), new CustomStreamHandler());
|
||||
}
|
||||
TestInput withUrlPrefix() {return inputWithUrlPrefix(this);}
|
||||
}
|
||||
|
||||
static URI uriWithUrlPrefix(URI uri) {
|
||||
return URI.create(stringWithUrlPrefix(uri.toString()));
|
||||
}
|
||||
|
||||
static String stringWithUrlPrefix(String uriStr) {
|
||||
if (uriStr.regionMatches(true, 0, "url:", 0, 4)) return uriStr;
|
||||
return RAND.nextBoolean() ? "url:" + uriStr : "Url:" + uriStr;
|
||||
}
|
||||
|
||||
static TestInput inputWithUrlPrefix(TestInput input) {
|
||||
String uriStr = input.uri();
|
||||
var handler = input.handler();
|
||||
|
||||
var urlUriStr = stringWithUrlPrefix(uriStr);
|
||||
if (uriStr.equals(urlUriStr)) return null;
|
||||
|
||||
var urlURI = URI.create(urlUriStr);
|
||||
try {
|
||||
new URL(null, urlURI.toString(), handler);
|
||||
} catch (Throwable t) {
|
||||
System.err.println("skipping new URL(null, \"" + urlURI + "\", handler): " + t);
|
||||
return null;
|
||||
}
|
||||
return new TestInput(urlUriStr, handler);
|
||||
}
|
||||
|
||||
static Stream<String> uris() {
|
||||
var uris = Stream.of(
|
||||
"http://jag:cafebabe@java.sun.com:94/b/c/d?q#g",
|
||||
"http://[1080:0:0:0:8:800:200C:417A]/index.html",
|
||||
"http://a/b/c/d;p?q",
|
||||
"mailto:mduerst@ifi.unizh.ch",
|
||||
"http:comp.infosystems.www.servers.unix",
|
||||
"http://j%41g:cafeb%41be@java.sun.com:94/%41/b/c/d?q#g",
|
||||
"jar:file:///x.jar!/",
|
||||
"jmod:/java.base",
|
||||
"jmod:///java.base");
|
||||
|
||||
if (hasFtp()) {
|
||||
uris = Stream.concat(uris,
|
||||
Stream.of("ftp://ftp.is.co.za/rfc/rfc1808.txt"));
|
||||
}
|
||||
|
||||
return uris;
|
||||
}
|
||||
|
||||
static Stream<String> nonOverridableUris() {
|
||||
return Stream.of("file:///nohost/%41/",
|
||||
"file://with.host/%41/",
|
||||
"file:/x/y/z",
|
||||
"jrt:/java.base/java/lang/Integer.class",
|
||||
"jrt:///java.base/java/lang/Integer.class");
|
||||
}
|
||||
static Stream<TestInput> withNoHandler() {
|
||||
return Stream.concat(uris(), nonOverridableUris())
|
||||
.map(TestInput::withNoHandler);
|
||||
}
|
||||
|
||||
static Stream<TestInput> withCustomHandler() {
|
||||
var withHandlers = uris()
|
||||
.map(TestInput::withNoHandler)
|
||||
.map(TestInput::withCustomHandler);
|
||||
return Stream.concat(withHandlers, Stream.of(
|
||||
new TestInput("foo:bar:baz", new CustomStreamHandler()),
|
||||
new TestInput("jar:file:///x.jar!/", new CustomStreamHandler()),
|
||||
new TestInput("jar:jar:file///x.jar!/bing", new CustomStreamHandler()),
|
||||
new TestInput("blah://localhost:80/x/y/z", new CustomStreamHandler())
|
||||
));
|
||||
}
|
||||
|
||||
static Stream<TestInput> overridingNonOverridable() {
|
||||
return nonOverridableUris().map(TestInput::withNoHandler)
|
||||
.map(TestInput::withCustomHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkExceptions() {
|
||||
var noscheme = URI.create("http");
|
||||
var unknown = URI.create("unknown:///foo/bar");
|
||||
var opaque = URI.create("opaque:opaque-path");
|
||||
var jrt = URI.create("jrt:/java.base/java.lang.Integer.class");
|
||||
var file = URI.create("file:/");
|
||||
var unoscheme = uriWithUrlPrefix(noscheme);
|
||||
var uunknown = uriWithUrlPrefix(unknown);
|
||||
var uopaque = uriWithUrlPrefix(opaque);
|
||||
var ujrt = uriWithUrlPrefix(jrt);
|
||||
var ufile = uriWithUrlPrefix(file);
|
||||
var handler = new CustomStreamHandler();
|
||||
assertThrows(NullPointerException.class, () -> URL.of(null, null));
|
||||
assertThrows(NullPointerException.class, () -> URL.of(null, handler));
|
||||
assertThrows(IllegalArgumentException.class, () -> URL.of(noscheme, null));
|
||||
assertThrows(IllegalArgumentException.class, () -> URL.of(noscheme, handler));
|
||||
assertThrows(IllegalArgumentException.class, () -> URL.of(jrt, handler));
|
||||
assertThrows(IllegalArgumentException.class, () -> URL.of(file, handler));
|
||||
assertThrows(IllegalArgumentException.class, () -> URL.of(ujrt, handler));
|
||||
assertThrows(IllegalArgumentException.class, () -> URL.of(ufile, handler));
|
||||
assertThrows(MalformedURLException.class, () -> URL.of(unknown, null));
|
||||
assertThrows(MalformedURLException.class, () -> URL.of(opaque, null));
|
||||
assertThrows(MalformedURLException.class, () -> URL.of(uunknown, null));
|
||||
assertThrows(MalformedURLException.class, () -> URL.of(uopaque, null));
|
||||
assertThrows(MalformedURLException.class, () -> URL.of(unoscheme, null));
|
||||
assertThrows(MalformedURLException.class, () -> URL.of(unoscheme, handler));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(value = "withNoHandler")
|
||||
public void testWithNoHandler(TestInput input) throws Exception {
|
||||
String uriStr = input.uri();
|
||||
URLStreamHandler handler = input.handler();
|
||||
System.err.println("testWithNoHandler: " + uriStr);
|
||||
assertNull(handler, input + ": input handler");
|
||||
URI uri = new URI(uriStr);
|
||||
URL url = URL.of(uri, handler);
|
||||
checkNoHandler(input, uri, url);
|
||||
var urlInput = input.withUrlPrefix();
|
||||
if (urlInput != null) {
|
||||
try {
|
||||
var urlURI = URI.create(input.uri());
|
||||
checkNoHandler(urlInput, uri, URL.of(urlURI, null));
|
||||
} catch (Throwable x) {
|
||||
throw new AssertionError("Failed: " + urlInput.uri() + " with: " + x, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNoHandler(TestInput input, URI uri, URL url) throws Exception {
|
||||
System.err.println("Testing: " + uri);
|
||||
checkURL(input, uri, url);
|
||||
URLStreamHandler urlHandler = URLAccess.getHandler(url);
|
||||
assertNotNull(urlHandler, input + ": URL.handler");
|
||||
assertNull(urlHandler.getClass().getClassLoader(),
|
||||
input + ": URL.handler class loader");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(value = "withCustomHandler")
|
||||
public void checkCustomHandler(TestInput input) throws Exception {
|
||||
String uriStr = input.uri();
|
||||
URLStreamHandler handler = input.handler();
|
||||
System.err.println("testWithCustomHandler: " + input);
|
||||
assertNotNull(handler, input + ": input handler");
|
||||
URI uri = new URI(uriStr);
|
||||
URL url = URL.of(uri, handler);
|
||||
checkCustomHandler(input, uri, url, handler);
|
||||
var urlInput = input.withUrlPrefix();
|
||||
if (urlInput != null) {
|
||||
urlInput = urlInput.withCustomHandler();
|
||||
handler = urlInput.handler();
|
||||
try {
|
||||
var urlURI = URI.create(urlInput.uri());
|
||||
checkCustomHandler(urlInput, uri, URL.of(urlURI, handler), handler);
|
||||
} catch (Throwable x) {
|
||||
throw new AssertionError("Failed with handler: " + urlInput.uri() + " with: " + x, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCustomHandler(TestInput input, URI uri, URL url,
|
||||
URLStreamHandler handler) throws Exception {
|
||||
System.err.println("Testing: " + uri);
|
||||
checkURL(input, uri, url);
|
||||
URLStreamHandler urlHandler = URLAccess.getHandler(url);
|
||||
assertSame(handler, urlHandler, input + ": URL.handler");
|
||||
URLConnection c = url.openConnection();
|
||||
assertNotNull(c, input + ": opened connection");
|
||||
assertEquals(CustomURLConnection.class, c.getClass(),
|
||||
input + ": connection class");
|
||||
assertEquals(CustomStreamHandler.class, urlHandler.getClass(),
|
||||
input + ": handler class");
|
||||
assertEquals(((CustomURLConnection)c).handler, handler, input + ": handler");
|
||||
assertEquals(c.getURL(), url, input + ": connection url");
|
||||
var customHandler = (CustomStreamHandler)urlHandler;
|
||||
assertEquals(customHandler.parseURLCalled(), 1, "parseURL calls");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(value = "overridingNonOverridable")
|
||||
public void testOverridingNonOverridable(TestInput input) throws Exception {
|
||||
String uriStr = input.uri();
|
||||
URLStreamHandler handler = input.handler();
|
||||
System.err.println("testOverridingNonOverridable: " + input);
|
||||
assertNotNull(handler, input + ": input handler");
|
||||
URI uri = new URI(uriStr);
|
||||
try {
|
||||
URL url = URL.of(uri, handler);
|
||||
throw new AssertionError("Should not be able to specify handler for: " + uriStr);
|
||||
} catch (IllegalArgumentException x) {
|
||||
System.err.println("Got expected exception: " + x);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFileBased(URI uri) {
|
||||
String scheme = uri.getScheme();
|
||||
boolean isJrt = "jrt".equals(scheme.toLowerCase(Locale.ROOT));
|
||||
boolean isJmod = "jmod".equals(scheme.toLowerCase(Locale.ROOT));
|
||||
boolean isFile = "file".equals(scheme.toLowerCase(Locale.ROOT));
|
||||
return isJmod || isJrt || isFile;
|
||||
}
|
||||
|
||||
private static void checkURL(TestInput input, URI uri, URL url) throws MalformedURLException {
|
||||
String scheme = uri.getScheme();
|
||||
assertEquals(scheme, url.getProtocol(), input + ": scheme");
|
||||
|
||||
if (uri.isOpaque()) {
|
||||
String ssp = uri.getSchemeSpecificPart();
|
||||
assertEquals(ssp, url.getPath(), input + ": ssp");
|
||||
} else {
|
||||
String authority = uri.getRawAuthority();
|
||||
boolean isHierarchical = uri.toString().startsWith(scheme + "://");
|
||||
boolean isFileBased = isFileBased(uri);
|
||||
|
||||
// Network based URLs usually follow URI, but file based
|
||||
// protocol handlers have a few discrepancies in how they
|
||||
// treat an absent authority:
|
||||
// - URI authority is null if there is no authority, always
|
||||
// - URL authority is null or empty depending on the protocol
|
||||
// and on whether the URL is hierarchical or not.
|
||||
if (isFileBased && authority == null) {
|
||||
// jrt: takes a fastpath - so that jrt:/ is equivalent to jrt:///
|
||||
if (scheme.equals("jrt")) {
|
||||
authority = "";
|
||||
}
|
||||
if (isHierarchical) {
|
||||
authority = "";
|
||||
}
|
||||
}
|
||||
assertEquals(authority, url.getAuthority(), input + ": authority");
|
||||
|
||||
// Network based URLs usually follow URI, but file based
|
||||
// protocol handlers have a few discrepancies in how they
|
||||
// treat an absent host:
|
||||
String host = uri.getHost();
|
||||
if (isFileBased && host == null) {
|
||||
host = "";
|
||||
}
|
||||
|
||||
assertEquals(host, url.getHost(), input + ": host");
|
||||
if (host != null) {
|
||||
String userInfo = uri.getRawUserInfo();
|
||||
assertEquals(userInfo, url.getUserInfo(), input + ": userInfo");
|
||||
assertEquals(uri.getPort(), url.getPort(), input + ": port");
|
||||
}
|
||||
|
||||
String path = uri.getRawPath();
|
||||
assertEquals(path, url.getPath(), input + ": path");
|
||||
|
||||
String query = uri.getQuery();
|
||||
assertEquals(query, url.getQuery(), input + ": query");
|
||||
}
|
||||
String frag = uri.getRawFragment();
|
||||
assertEquals(frag, url.getRef(), input + ": fragment");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static boolean hasFtp() {
|
||||
try {
|
||||
return new java.net.URL("ftp://localhost/") != null;
|
||||
} catch (java.net.MalformedURLException x) {
|
||||
System.err.println("FTP not supported by this runtime.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static class CustomURLConnection extends URLConnection {
|
||||
|
||||
public final CustomStreamHandler handler;
|
||||
CustomURLConnection(CustomStreamHandler handler, URL url) {
|
||||
super(url);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
static class CustomStreamHandler extends URLStreamHandler {
|
||||
|
||||
final AtomicInteger parseURLCalled = new AtomicInteger();
|
||||
|
||||
@Override
|
||||
protected void parseURL(URL u, String spec, int start, int limit) {
|
||||
parseURLCalled.incrementAndGet();
|
||||
super.parseURL(u, spec, start, limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URLConnection openConnection(URL u) throws IOException {
|
||||
return new CustomURLConnection(this, u);
|
||||
}
|
||||
|
||||
public int parseURLCalled() {
|
||||
return parseURLCalled.get();
|
||||
}
|
||||
}
|
||||
|
||||
static final class URLAccess {
|
||||
static final VarHandle HANDLER;
|
||||
static {
|
||||
try {
|
||||
Lookup lookup = MethodHandles.privateLookupIn(URL.class, MethodHandles.lookup());
|
||||
HANDLER = lookup.findVarHandle(URL.class, "handler", URLStreamHandler.class);
|
||||
} catch (Exception x) {
|
||||
throw new ExceptionInInitializerError(x);
|
||||
}
|
||||
}
|
||||
static URLStreamHandler getHandler(URL url) {
|
||||
return (URLStreamHandler)HANDLER.get(url);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 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
|
||||
@ -72,6 +72,7 @@ public class ThreadLocalParseUtil {
|
||||
|
||||
@Benchmark
|
||||
public URI appendEncodedTest() throws Throwable {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL url = new URL("https://example.com/xyz/abc/def?query=#30");
|
||||
return (URI) MH_TO_URI.invokeExact(url);
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ public class ProtectionDomainBench {
|
||||
cs = new CodeSource[numberOfCodeSources];
|
||||
|
||||
for (int i = 0; i < numberOfCodeSources; i++) {
|
||||
@SuppressWarnings("deprecation")
|
||||
URL u = new URL("file:/tmp/duke" + i);
|
||||
cs[i] = new CodeSource(u, (java.security.cert.Certificate[]) null);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user