8258422: Cleanup unnecessary null comparison before instanceof check in java.base

Reviewed-by: chegar, aefimov
This commit is contained in:
Andrey Turbanov 2021-01-11 23:30:44 +00:00 committed by Aleksei Efimov
parent ff54b77b76
commit 022bc9f0cb
22 changed files with 69 additions and 81 deletions

View file

@ -66,8 +66,8 @@ public abstract class Negotiator {
} catch (ReflectiveOperationException roe) {
finest(roe);
Throwable t = roe.getCause();
if (t != null && t instanceof Exception)
finest((Exception)t);
if (t instanceof Exception exception)
finest(exception);
return null;
}
}

View file

@ -426,7 +426,7 @@ final class HttpsClient extends HttpClient
// unconnected sockets have not been implemented.
//
Throwable t = se.getCause();
if (t != null && t instanceof UnsupportedOperationException) {
if (t instanceof UnsupportedOperationException) {
return super.createSocket();
} else {
throw se;

View file

@ -504,9 +504,9 @@ public class DatagramSocketAdaptor
* @throws SocketException if group is not a multicast address
*/
private static InetAddress checkGroup(SocketAddress mcastaddr) throws SocketException {
if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
if (!(mcastaddr instanceof InetSocketAddress addr))
throw new IllegalArgumentException("Unsupported address type");
InetAddress group = ((InetSocketAddress) mcastaddr).getAddress();
InetAddress group = addr.getAddress();
if (group == null)
throw new IllegalArgumentException("Unresolved address");
if (!group.isMulticastAddress())

View file

@ -149,8 +149,8 @@ class PollingWatchService
});
} catch (PrivilegedActionException pae) {
Throwable cause = pae.getCause();
if (cause != null && cause instanceof IOException)
throw (IOException)cause;
if (cause instanceof IOException ioe)
throw ioe;
throw new AssertionError(pae);
}
}