Skip to content

Commit 83fd8d7

Browse files
authored
HDDS-12449. Enable UseCollectionIsEmpty check in PMD (#7995)
1 parent d18da13 commit 83fd8d7

File tree

156 files changed

+250
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+250
-251
lines changed

dev-support/pmd/pmd-ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<rule ref="category/java/bestpractices.xml/MissingOverride"/>
3131
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
3232
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
33+
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />
3334

3435
<exclude-pattern>.*/generated-sources/.*</exclude-pattern>
3536
</ruleset>

hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ protected synchronized int readWithStrategy(ByteReaderStrategy strategy)
366366
int len = strategy.getTargetLength();
367367
while (len > 0) {
368368
// if we are at the last chunk and have read the entire chunk, return
369-
if (chunkStreams.size() == 0 ||
369+
if (chunkStreams.isEmpty() ||
370370
(chunkStreams.size() - 1 <= chunkIndex &&
371371
chunkStreams.get(chunkIndex)
372372
.getRemaining() == 0)) {

hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ECBlockOutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ ContainerCommandResponseProto> executePutBlock(boolean close,
131131
blockID = bd.getBlockID();
132132
}
133133
List<ChunkInfo> chunks = bd.getChunks();
134-
if (chunks != null && chunks.size() > 0) {
134+
if (chunks != null && !chunks.isEmpty()) {
135135
if (chunks.get(0).hasStripeChecksum()) {
136136
checksumBlockData = bd;
137137
break;

hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/MultipartInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected synchronized int readWithStrategy(ByteReaderStrategy strategy)
8383

8484
int totalReadLen = 0;
8585
while (strategy.getTargetLength() > 0) {
86-
if (partStreams.size() == 0 ||
86+
if (partStreams.isEmpty() ||
8787
partStreams.size() - 1 <= partIndex &&
8888
partStreams.get(partIndex).getRemaining() == 0) {
8989
return totalReadLen == 0 ? EOF : totalReadLen;

hadoop-hdds/client/src/main/java/org/apache/hadoop/ozone/client/io/ECBlockInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public synchronized int read(ByteBuffer byteBuffer) throws IOException {
335335

336336
protected boolean shouldRetryFailedRead(int failedIndex) {
337337
Deque<DatanodeDetails> spareLocations = spareDataLocations.get(failedIndex);
338-
if (spareLocations != null && spareLocations.size() > 0) {
338+
if (spareLocations != null && !spareLocations.isEmpty()) {
339339
failedLocations.add(dataLocations[failedIndex]);
340340
DatanodeDetails spare = spareLocations.removeFirst();
341341
dataLocations[failedIndex] = spare;

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static Optional<String> getHostName(String value) {
207207
return Optional.empty();
208208
}
209209
String hostname = value.replaceAll("\\:[0-9]+$", "");
210-
if (hostname.length() == 0) {
210+
if (hostname.isEmpty()) {
211211
return Optional.empty();
212212
} else {
213213
return Optional.of(hostname);

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMNodeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static List<SCMNodeInfo> buildNodeInfo(ConfigurationSource conf) {
7979
if (scmServiceId != null) {
8080
ArrayList< String > scmNodeIds = new ArrayList<>(
8181
HddsUtils.getSCMNodeIds(conf, scmServiceId));
82-
if (scmNodeIds.size() == 0) {
82+
if (scmNodeIds.isEmpty()) {
8383
throw new ConfigurationException(
8484
String.format("Configuration does not have any value set for %s " +
8585
"for the SCM serviceId %s. List of SCM Node ID's should " +

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/InnerNodeImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ private Map<Node, Integer> getAncestorCountMap(Collection<Node> nodes,
574574
Preconditions.checkState(genToExclude >= 0);
575575
Preconditions.checkState(genToReturn >= 0);
576576

577-
if (nodes == null || nodes.size() == 0) {
577+
if (nodes == null || nodes.isEmpty()) {
578578
return Collections.emptyMap();
579579
}
580580
// with the recursive call, genToReturn can be smaller than genToExclude
@@ -619,7 +619,7 @@ private Node getLeafOnLeafParent(int leafIndex, List<String> excludedScopes,
619619
if (excludedNodes != null && excludedNodes.contains(node)) {
620620
continue;
621621
}
622-
if (excludedScopes != null && excludedScopes.size() > 0) {
622+
if (excludedScopes != null && !excludedScopes.isEmpty()) {
623623
if (excludedScopes.stream().anyMatch(node::isDescendant)) {
624624
continue;
625625
}

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/security/ssl/ReloadingX509KeyManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private X509ExtendedKeyManager init(PrivateKey newPrivateKey, List<X509Certifica
221221

222222
private boolean isAlreadyUsing(PrivateKey privateKey, List<X509Certificate> newTrustChain) {
223223
return currentPrivateKey != null && currentPrivateKey.equals(privateKey) &&
224-
currentTrustChain.size() > 0 &&
224+
!currentTrustChain.isEmpty() &&
225225
newTrustChain.size() == currentTrustChain.size() &&
226226
newTrustChain.stream()
227227
.allMatch(

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/security/ssl/ReloadingX509TrustManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private X509TrustManager init(List<X509Certificate> newRootCaCerts)
161161
}
162162

163163
private boolean isAlreadyUsing(List<X509Certificate> newRootCaCerts) {
164-
return newRootCaCerts.size() > 0 &&
164+
return !newRootCaCerts.isEmpty() &&
165165
currentRootCACerts.size() == newRootCaCerts.size() &&
166166
newRootCaCerts.stream()
167167
.allMatch(

0 commit comments

Comments
 (0)