From d8ec8ab9653f628fa6ed16baf4c9e7681266ae8f Mon Sep 17 00:00:00 2001 From: Jack Jiang <81204396+TJJack@users.noreply.github.com> Date: Tue, 23 Mar 2021 23:46:11 +0800 Subject: [PATCH] HADOOP-17599. Remove NULL checks before instanceof (#2804) --- .../main/java/org/apache/hadoop/fs/AbstractFileSystem.java | 2 +- .../java/org/apache/hadoop/fs/DelegationTokenRenewer.java | 2 +- .../src/main/java/org/apache/hadoop/fs/FileChecksum.java | 2 +- .../src/main/java/org/apache/hadoop/oncrpc/RpcCallCache.java | 2 +- .../org/apache/hadoop/fs/azure/MockWasbAuthorizerImpl.java | 3 +-- .../api/protocolrecords/GetAllResourceProfilesResponse.java | 2 +- .../api/protocolrecords/GetAllResourceTypeInfoResponse.java | 2 +- .../yarn/api/protocolrecords/GetResourceProfileRequest.java | 2 +- .../yarn/api/protocolrecords/GetResourceProfileResponse.java | 2 +- .../hadoop/yarn/api/records/impl/LightWeightResource.java | 2 +- .../hadoop/yarn/util/Log4jWarningErrorMetricsAppender.java | 2 +- .../org/apache/hadoop/yarn/server/volume/csi/VolumeId.java | 2 +- .../linux/privileged/PrivilegedOperation.java | 2 +- .../resourceplugin/deviceframework/AssignedDevice.java | 4 ++-- .../resourceplugin/gpu/AssignedGpuDevice.java | 4 ++-- .../containermanager/resourceplugin/gpu/GpuDevice.java | 4 ++-- .../containermanager/runtime/ContainerRuntimeContext.java | 2 +- 17 files changed, 20 insertions(+), 21 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java index 5796f230262..d50cf1e03ac 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java @@ -1353,7 +1353,7 @@ public abstract class AbstractFileSystem implements PathCapabilities { @Override //Object public boolean equals(Object other) { - if (other == null || !(other instanceof AbstractFileSystem)) { + if (!(other instanceof AbstractFileSystem)) { return false; } return myUri.equals(((AbstractFileSystem) other).myUri); diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java index 19c29cfa3da..38a7344d4f9 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java @@ -97,7 +97,7 @@ public class DelegationTokenRenewer public boolean equals(final Object that) { if (this == that) { return true; - } else if (that == null || !(that instanceof RenewAction)) { + } else if (!(that instanceof RenewAction)) { return false; } return token.equals(((RenewAction)that).token); diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileChecksum.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileChecksum.java index 62f1a9b3f48..6822fa48562 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileChecksum.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileChecksum.java @@ -47,7 +47,7 @@ public abstract class FileChecksum implements Writable { if (other == this) { return true; } - if (other == null || !(other instanceof FileChecksum)) { + if (!(other instanceof FileChecksum)) { return false; } diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCallCache.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCallCache.java index 8632a387c60..d6bd492042d 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCallCache.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCallCache.java @@ -93,7 +93,7 @@ public class RpcCallCache { if (this == obj) { return true; } - if (obj == null || !(obj instanceof ClientRequest)) { + if (!(obj instanceof ClientRequest)) { return false; } ClientRequest other = (ClientRequest) obj; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/MockWasbAuthorizerImpl.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/MockWasbAuthorizerImpl.java index 1f5072d58ed..d6f26d702c8 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/MockWasbAuthorizerImpl.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/MockWasbAuthorizerImpl.java @@ -188,8 +188,7 @@ public class MockWasbAuthorizerImpl implements WasbAuthorizerInterface { return true; } - if (obj == null - || !(obj instanceof AuthorizationComponent)) { + if (!(obj instanceof AuthorizationComponent)) { return false; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceProfilesResponse.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceProfilesResponse.java index 547770890d5..d6852f1d076 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceProfilesResponse.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceProfilesResponse.java @@ -45,7 +45,7 @@ public abstract class GetAllResourceProfilesResponse { if (this == other) { return true; } - if (other == null || !(other instanceof GetAllResourceProfilesResponse)) { + if (!(other instanceof GetAllResourceProfilesResponse)) { return false; } return ((GetAllResourceProfilesResponse) other).getResourceProfiles() diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceTypeInfoResponse.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceTypeInfoResponse.java index b57b96df3fd..dca9fe5e238 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceTypeInfoResponse.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetAllResourceTypeInfoResponse.java @@ -45,7 +45,7 @@ public abstract class GetAllResourceTypeInfoResponse { if (this == other) { return true; } - if (other == null || !(other instanceof GetAllResourceTypeInfoResponse)) { + if (!(other instanceof GetAllResourceTypeInfoResponse)) { return false; } return ((GetAllResourceTypeInfoResponse) other).getResourceTypeInfo() diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileRequest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileRequest.java index 3655be946da..2588bb9006c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileRequest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileRequest.java @@ -45,7 +45,7 @@ public abstract class GetResourceProfileRequest { if (this == other) { return true; } - if (other == null || !(other instanceof GetResourceProfileRequest)) { + if (!(other instanceof GetResourceProfileRequest)) { return false; } return this.getProfileName() diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileResponse.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileResponse.java index a010644a792..7aa20c51bc0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileResponse.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/GetResourceProfileResponse.java @@ -54,7 +54,7 @@ public abstract class GetResourceProfileResponse { return true; } - if (other == null || !(other instanceof GetResourceProfileResponse)) { + if (!(other instanceof GetResourceProfileResponse)) { return false; } return this.getResource() diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java index 02afe50cc23..8172128607a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java @@ -139,7 +139,7 @@ public class LightWeightResource extends Resource { if (this == obj) { return true; } - if (obj == null || !(obj instanceof Resource)) { + if (!(obj instanceof Resource)) { return false; } Resource other = (Resource) obj; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/Log4jWarningErrorMetricsAppender.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/Log4jWarningErrorMetricsAppender.java index 9f5de8c1517..fffc8a857cb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/Log4jWarningErrorMetricsAppender.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/Log4jWarningErrorMetricsAppender.java @@ -68,7 +68,7 @@ public class Log4jWarningErrorMetricsAppender extends AppenderSkeleton { @Override public boolean equals(Object e) { - if (e == null || !(e instanceof PurgeElement)) { + if (!(e instanceof PurgeElement)) { return false; } if (e == this) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/volume/csi/VolumeId.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/volume/csi/VolumeId.java index 8acc95e4d9a..54870385ffc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/volume/csi/VolumeId.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/volume/csi/VolumeId.java @@ -43,7 +43,7 @@ public class VolumeId { @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof VolumeId)) { + if (!(obj instanceof VolumeId)) { return false; } return StringUtils.equalsIgnoreCase(volumeId, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/PrivilegedOperation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/PrivilegedOperation.java index 979f4821b24..e50d17d5c7b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/PrivilegedOperation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/privileged/PrivilegedOperation.java @@ -135,7 +135,7 @@ public class PrivilegedOperation { @Override public boolean equals(Object other) { - if (other == null || !(other instanceof PrivilegedOperation)) { + if (!(other instanceof PrivilegedOperation)) { return false; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/AssignedDevice.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/AssignedDevice.java index cad95ab9dc4..e5ae1a2dc95 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/AssignedDevice.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/deviceframework/AssignedDevice.java @@ -49,7 +49,7 @@ public class AssignedDevice implements Serializable, Comparable { @Override public int compareTo(Object o) { - if (o == null || !(o instanceof AssignedDevice)) { + if (!(o instanceof AssignedDevice)) { return -1; } AssignedDevice other = (AssignedDevice) o; @@ -62,7 +62,7 @@ public class AssignedDevice implements Serializable, Comparable { @Override public boolean equals(Object o) { - if (o == null || !(o instanceof AssignedDevice)) { + if (!(o instanceof AssignedDevice)) { return false; } AssignedDevice other = (AssignedDevice) o; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/AssignedGpuDevice.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/AssignedGpuDevice.java index 26fd9050742..e16423fd984 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/AssignedGpuDevice.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/AssignedGpuDevice.java @@ -44,7 +44,7 @@ public class AssignedGpuDevice extends GpuDevice { @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof AssignedGpuDevice)) { + if (!(obj instanceof AssignedGpuDevice)) { return false; } AssignedGpuDevice other = (AssignedGpuDevice) obj; @@ -54,7 +54,7 @@ public class AssignedGpuDevice extends GpuDevice { @Override public int compareTo(Object obj) { - if (obj == null || (!(obj instanceof AssignedGpuDevice))) { + if ((!(obj instanceof AssignedGpuDevice))) { return -1; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/GpuDevice.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/GpuDevice.java index bce1d9fa480..cdfc6fab29f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/GpuDevice.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/GpuDevice.java @@ -43,7 +43,7 @@ public class GpuDevice implements Serializable, Comparable { @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof GpuDevice)) { + if (!(obj instanceof GpuDevice)) { return false; } GpuDevice other = (GpuDevice) obj; @@ -52,7 +52,7 @@ public class GpuDevice implements Serializable, Comparable { @Override public int compareTo(Object obj) { - if (obj == null || (!(obj instanceof GpuDevice))) { + if (!(obj instanceof GpuDevice)) { return -1; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerRuntimeContext.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerRuntimeContext.java index 4194b993006..1cf899d77dd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerRuntimeContext.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerRuntimeContext.java @@ -54,7 +54,7 @@ public final class ContainerRuntimeContext { @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof Attribute)){ + if (!(obj instanceof Attribute)){ return false; }