8263233: Update java.net and java.nio to use instanceof pattern variable
Reviewed-by: dfuchs, bpb, chegar, michaelm
This commit is contained in:
parent
3fe8a4661c
commit
fdd3941121
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2021, 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
|
||||
@ -80,10 +80,9 @@ import java.util.Set;
|
||||
super(delegate);
|
||||
this.socket = socket;
|
||||
SocketAddress a = proxy.address();
|
||||
if ( !(a instanceof InetSocketAddress) )
|
||||
if ( !(a instanceof InetSocketAddress ad) )
|
||||
throw new IllegalArgumentException("Unsupported address type");
|
||||
|
||||
InetSocketAddress ad = (InetSocketAddress) a;
|
||||
server = ad.getHostString();
|
||||
port = ad.getPort();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -715,9 +715,8 @@ public final class HttpCookie implements Cloneable {
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (!(obj instanceof HttpCookie))
|
||||
if (!(obj instanceof HttpCookie other))
|
||||
return false;
|
||||
HttpCookie other = (HttpCookie)obj;
|
||||
|
||||
// One http cookie is equal to another cookie (RFC 2965 sec. 3.3.3) if:
|
||||
// 1. they come from same domain (case-insensitive),
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
@ -262,10 +262,9 @@ class Inet6Address extends InetAddress {
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (! (o instanceof Inet6AddressHolder)) {
|
||||
if (!(o instanceof Inet6AddressHolder that)) {
|
||||
return false;
|
||||
}
|
||||
Inet6AddressHolder that = (Inet6AddressHolder)o;
|
||||
|
||||
return Arrays.equals(this.ipaddress, that.ipaddress);
|
||||
}
|
||||
@ -525,10 +524,9 @@ class Inet6Address extends InetAddress {
|
||||
Enumeration<InetAddress> addresses = ifc.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
InetAddress addr = addresses.nextElement();
|
||||
if (!(addr instanceof Inet6Address)) {
|
||||
if (!(addr instanceof Inet6Address ia6_addr)) {
|
||||
continue;
|
||||
}
|
||||
Inet6Address ia6_addr = (Inet6Address)addr;
|
||||
/* check if site or link local prefixes match */
|
||||
if (!isDifferentLocalAddressType(thisAddr, ia6_addr.getAddress())){
|
||||
/* type not the same, so carry on searching */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -101,17 +101,10 @@ public class InterfaceAddress {
|
||||
* @see java.net.InterfaceAddress#hashCode()
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof InterfaceAddress) {
|
||||
InterfaceAddress cmp = (InterfaceAddress) obj;
|
||||
|
||||
if (Objects.equals(address, cmp.address) &&
|
||||
return obj instanceof InterfaceAddress cmp &&
|
||||
Objects.equals(address, cmp.address) &&
|
||||
Objects.equals(broadcast, cmp.broadcast) &&
|
||||
maskLength == cmp.maskLength)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
maskLength == cmp.maskLength;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2021, 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
|
||||
@ -216,9 +216,8 @@ final class NetMulticastSocket extends MulticastSocket {
|
||||
throw new SocketException("already bound");
|
||||
if (addr == null)
|
||||
addr = new InetSocketAddress(0);
|
||||
if (!(addr instanceof InetSocketAddress))
|
||||
if (!(addr instanceof InetSocketAddress epoint))
|
||||
throw new IllegalArgumentException("Unsupported address type!");
|
||||
InetSocketAddress epoint = (InetSocketAddress) addr;
|
||||
if (epoint.isUnresolved())
|
||||
throw new SocketException("Unresolved address");
|
||||
InetAddress iaddr = epoint.getAddress();
|
||||
@ -259,9 +258,8 @@ final class NetMulticastSocket extends MulticastSocket {
|
||||
public void connect(SocketAddress addr) throws SocketException {
|
||||
if (addr == null)
|
||||
throw new IllegalArgumentException("Address can't be null");
|
||||
if (!(addr instanceof InetSocketAddress))
|
||||
if (!(addr instanceof InetSocketAddress epoint))
|
||||
throw new IllegalArgumentException("Unsupported address type");
|
||||
InetSocketAddress epoint = (InetSocketAddress) addr;
|
||||
if (epoint.isUnresolved())
|
||||
throw new SocketException("Unresolved address");
|
||||
connectInternal(epoint.getAddress(), epoint.getPort());
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
@ -590,10 +590,9 @@ public final class NetworkInterface {
|
||||
* @see java.net.InetAddress#getAddress()
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof NetworkInterface)) {
|
||||
if (!(obj instanceof NetworkInterface that)) {
|
||||
return false;
|
||||
}
|
||||
NetworkInterface that = (NetworkInterface)obj;
|
||||
if (this.name != null ) {
|
||||
if (!this.name.equals(that.name)) {
|
||||
return false;
|
||||
|
@ -373,9 +373,8 @@ public class ServerSocket implements java.io.Closeable {
|
||||
throw new SocketException("Already bound");
|
||||
if (endpoint == null)
|
||||
endpoint = new InetSocketAddress(0);
|
||||
if (!(endpoint instanceof InetSocketAddress))
|
||||
if (!(endpoint instanceof InetSocketAddress epoint))
|
||||
throw new IllegalArgumentException("Unsupported address type");
|
||||
InetSocketAddress epoint = (InetSocketAddress) endpoint;
|
||||
if (epoint.isUnresolved())
|
||||
throw new SocketException("Unresolved address");
|
||||
if (backlog < 1)
|
||||
|
@ -611,10 +611,9 @@ public class Socket implements java.io.Closeable {
|
||||
if (isConnected())
|
||||
throw new SocketException("already connected");
|
||||
|
||||
if (!(endpoint instanceof InetSocketAddress))
|
||||
if (!(endpoint instanceof InetSocketAddress epoint))
|
||||
throw new IllegalArgumentException("Unsupported address type");
|
||||
|
||||
InetSocketAddress epoint = (InetSocketAddress) endpoint;
|
||||
InetAddress addr = epoint.getAddress ();
|
||||
int port = epoint.getPort();
|
||||
checkAddress(addr, "connect");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2021, 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
|
||||
@ -860,14 +860,12 @@ public final class SocketPermission extends Permission
|
||||
public boolean implies(Permission p) {
|
||||
int i,j;
|
||||
|
||||
if (!(p instanceof SocketPermission))
|
||||
if (!(p instanceof SocketPermission that))
|
||||
return false;
|
||||
|
||||
if (p == this)
|
||||
return true;
|
||||
|
||||
SocketPermission that = (SocketPermission) p;
|
||||
|
||||
return ((this.mask & that.mask) == that.mask) &&
|
||||
impliesIgnoreMask(that);
|
||||
}
|
||||
@ -1040,11 +1038,9 @@ public final class SocketPermission extends Permission
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
if (! (obj instanceof SocketPermission))
|
||||
if (! (obj instanceof SocketPermission that))
|
||||
return false;
|
||||
|
||||
SocketPermission that = (SocketPermission) obj;
|
||||
|
||||
//this is (overly?) complex!!!
|
||||
|
||||
// check the mask first
|
||||
@ -1379,15 +1375,13 @@ final class SocketPermissionCollection extends PermissionCollection
|
||||
*/
|
||||
@Override
|
||||
public void add(Permission permission) {
|
||||
if (! (permission instanceof SocketPermission))
|
||||
if (! (permission instanceof SocketPermission sp))
|
||||
throw new IllegalArgumentException("invalid permission: "+
|
||||
permission);
|
||||
if (isReadOnly())
|
||||
throw new SecurityException(
|
||||
"attempt to add a Permission to a readonly PermissionCollection");
|
||||
|
||||
SocketPermission sp = (SocketPermission)permission;
|
||||
|
||||
// Add permission to map if it is absent, or replace with new
|
||||
// permission if applicable. NOTE: cannot use lambda for
|
||||
// remappingFunction parameter until JDK-8076596 is fixed.
|
||||
@ -1426,11 +1420,9 @@ final class SocketPermissionCollection extends PermissionCollection
|
||||
@Override
|
||||
public boolean implies(Permission permission)
|
||||
{
|
||||
if (! (permission instanceof SocketPermission))
|
||||
if (! (permission instanceof SocketPermission np))
|
||||
return false;
|
||||
|
||||
SocketPermission np = (SocketPermission) permission;
|
||||
|
||||
int desired = np.getMask();
|
||||
int effective = 0;
|
||||
int needed = desired;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
@ -57,8 +57,7 @@ class SocksSocketImpl extends DelegatingSocketImpl implements SocksConsts {
|
||||
SocksSocketImpl(Proxy proxy, SocketImpl delegate) {
|
||||
super(delegate);
|
||||
SocketAddress a = proxy.address();
|
||||
if (a instanceof InetSocketAddress) {
|
||||
InetSocketAddress ad = (InetSocketAddress) a;
|
||||
if (a instanceof InetSocketAddress ad) {
|
||||
// Use getHostString() to avoid reverse lookups
|
||||
server = ad.getHostString();
|
||||
serverPort = ad.getPort();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
@ -1501,9 +1501,8 @@ public final class URI
|
||||
public boolean equals(Object ob) {
|
||||
if (ob == this)
|
||||
return true;
|
||||
if (!(ob instanceof URI))
|
||||
if (!(ob instanceof URI that))
|
||||
return false;
|
||||
URI that = (URI)ob;
|
||||
if (this.isOpaque() != that.isOpaque()) return false;
|
||||
if (!equalIgnoringCase(this.scheme, that.scheme)) return false;
|
||||
if (!equal(this.fragment, that.fragment)) return false;
|
||||
|
@ -972,9 +972,8 @@ public final class URL implements java.io.Serializable {
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof URL))
|
||||
if (!(obj instanceof URL u2))
|
||||
return false;
|
||||
URL u2 = (URL)obj;
|
||||
|
||||
return handler.equals(this, u2);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2021, 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
|
||||
@ -288,8 +288,7 @@ public class URLClassLoader extends SecureClassLoader implements Closeable {
|
||||
}
|
||||
URLConnection urlc = url.openConnection();
|
||||
InputStream is = urlc.getInputStream();
|
||||
if (urlc instanceof JarURLConnection) {
|
||||
JarURLConnection juc = (JarURLConnection)urlc;
|
||||
if (urlc instanceof JarURLConnection juc) {
|
||||
JarFile jar = juc.getJarFile();
|
||||
synchronized (closeables) {
|
||||
if (!closeables.containsKey(jar)) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2021, 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
|
||||
@ -298,12 +298,10 @@ public final class URLPermission extends Permission {
|
||||
* </table>
|
||||
*/
|
||||
public boolean implies(Permission p) {
|
||||
if (! (p instanceof URLPermission)) {
|
||||
if (! (p instanceof URLPermission that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
URLPermission that = (URLPermission)p;
|
||||
|
||||
if (this.methods.isEmpty() && !that.methods.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -374,10 +372,9 @@ public final class URLPermission extends Permission {
|
||||
* and p's url equals this's url. Returns false otherwise.
|
||||
*/
|
||||
public boolean equals(Object p) {
|
||||
if (!(p instanceof URLPermission)) {
|
||||
if (!(p instanceof URLPermission that)) {
|
||||
return false;
|
||||
}
|
||||
URLPermission that = (URLPermission)p;
|
||||
if (!this.scheme.equals(that.scheme)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2021, 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
|
||||
@ -194,9 +194,8 @@ public final class UnixDomainSocketAddress extends SocketAddress {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof UnixDomainSocketAddress))
|
||||
if (!(o instanceof UnixDomainSocketAddress that))
|
||||
return false;
|
||||
UnixDomainSocketAddress that = (UnixDomainSocketAddress)o;
|
||||
return this.path.equals(that.path);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
@ -152,9 +152,8 @@ class StringCharBuffer // package-private
|
||||
public boolean equals(Object ob) {
|
||||
if (this == ob)
|
||||
return true;
|
||||
if (!(ob instanceof CharBuffer))
|
||||
if (!(ob instanceof CharBuffer that))
|
||||
return false;
|
||||
CharBuffer that = (CharBuffer)ob;
|
||||
int thisPos = this.position();
|
||||
int thisRem = this.limit() - thisPos;
|
||||
int thatPos = that.position();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
@ -86,8 +86,7 @@ public final class Channels {
|
||||
private static void writeFully(WritableByteChannel ch, ByteBuffer bb)
|
||||
throws IOException
|
||||
{
|
||||
if (ch instanceof SelectableChannel) {
|
||||
SelectableChannel sc = (SelectableChannel) ch;
|
||||
if (ch instanceof SelectableChannel sc) {
|
||||
synchronized (sc.blockingLock()) {
|
||||
if (!sc.isBlocking())
|
||||
throw new IllegalBlockingModeException();
|
||||
|
Loading…
Reference in New Issue
Block a user