Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-support/pmd/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<rule ref="category/java/bestpractices.xml/MissingOverride"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />

<exclude-pattern>.*/generated-sources/.*</exclude-pattern>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ protected synchronized int readWithStrategy(ByteReaderStrategy strategy)
int len = strategy.getTargetLength();
while (len > 0) {
// if we are at the last chunk and have read the entire chunk, return
if (chunkStreams.size() == 0 ||
if (chunkStreams.isEmpty() ||
(chunkStreams.size() - 1 <= chunkIndex &&
chunkStreams.get(chunkIndex)
.getRemaining() == 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ContainerCommandResponseProto> executePutBlock(boolean close,
blockID = bd.getBlockID();
}
List<ChunkInfo> chunks = bd.getChunks();
if (chunks != null && chunks.size() > 0) {
if (chunks != null && !chunks.isEmpty()) {
if (chunks.get(0).hasStripeChecksum()) {
checksumBlockData = bd;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected synchronized int readWithStrategy(ByteReaderStrategy strategy)

int totalReadLen = 0;
while (strategy.getTargetLength() > 0) {
if (partStreams.size() == 0 ||
if (partStreams.isEmpty() ||
partStreams.size() - 1 <= partIndex &&
partStreams.get(partIndex).getRemaining() == 0) {
return totalReadLen == 0 ? EOF : totalReadLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public synchronized int read(ByteBuffer byteBuffer) throws IOException {

protected boolean shouldRetryFailedRead(int failedIndex) {
Deque<DatanodeDetails> spareLocations = spareDataLocations.get(failedIndex);
if (spareLocations != null && spareLocations.size() > 0) {
if (spareLocations != null && !spareLocations.isEmpty()) {
failedLocations.add(dataLocations[failedIndex]);
DatanodeDetails spare = spareLocations.removeFirst();
dataLocations[failedIndex] = spare;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static Optional<String> getHostName(String value) {
return Optional.empty();
}
String hostname = value.replaceAll("\\:[0-9]+$", "");
if (hostname.length() == 0) {
if (hostname.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(hostname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static List<SCMNodeInfo> buildNodeInfo(ConfigurationSource conf) {
if (scmServiceId != null) {
ArrayList< String > scmNodeIds = new ArrayList<>(
HddsUtils.getSCMNodeIds(conf, scmServiceId));
if (scmNodeIds.size() == 0) {
if (scmNodeIds.isEmpty()) {
throw new ConfigurationException(
String.format("Configuration does not have any value set for %s " +
"for the SCM serviceId %s. List of SCM Node ID's should " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ private Map<Node, Integer> getAncestorCountMap(Collection<Node> nodes,
Preconditions.checkState(genToExclude >= 0);
Preconditions.checkState(genToReturn >= 0);

if (nodes == null || nodes.size() == 0) {
if (nodes == null || nodes.isEmpty()) {
return Collections.emptyMap();
}
// with the recursive call, genToReturn can be smaller than genToExclude
Expand Down Expand Up @@ -619,7 +619,7 @@ private Node getLeafOnLeafParent(int leafIndex, List<String> excludedScopes,
if (excludedNodes != null && excludedNodes.contains(node)) {
continue;
}
if (excludedScopes != null && excludedScopes.size() > 0) {
if (excludedScopes != null && !excludedScopes.isEmpty()) {
if (excludedScopes.stream().anyMatch(node::isDescendant)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private X509ExtendedKeyManager init(PrivateKey newPrivateKey, List<X509Certifica

private boolean isAlreadyUsing(PrivateKey privateKey, List<X509Certificate> newTrustChain) {
return currentPrivateKey != null && currentPrivateKey.equals(privateKey) &&
currentTrustChain.size() > 0 &&
!currentTrustChain.isEmpty() &&
newTrustChain.size() == currentTrustChain.size() &&
newTrustChain.stream()
.allMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private X509TrustManager init(List<X509Certificate> newRootCaCerts)
}

private boolean isAlreadyUsing(List<X509Certificate> newRootCaCerts) {
return newRootCaCerts.size() > 0 &&
return !newRootCaCerts.isEmpty() &&
currentRootCACerts.size() == newRootCaCerts.size() &&
newRootCaCerts.stream()
.allMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private X509Certificate generateCertificate(BigInteger caCertSerialId) throws Op
int keyUsageFlag = KeyUsage.keyCertSign | KeyUsage.cRLSign;
KeyUsage keyUsage = new KeyUsage(keyUsageFlag);
builder.addExtension(Extension.keyUsage, true, keyUsage);
if (altNames != null && altNames.size() >= 1) {
if (altNames != null && !altNames.isEmpty()) {
builder.addExtension(new Extension(Extension.subjectAlternativeName,
false, new GeneralNames(altNames.toArray(
new GeneralName[altNames.size()])).getEncoded()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public JaegerSpanContext extract(StringBuilder s) {
throw new MalformedTracerStateStringException(value);
} else {
String traceId = parts[0];
if (traceId.length() <= 32 && traceId.length() >= 1) {
if (traceId.length() <= 32 && !traceId.isEmpty()) {
return new JaegerSpanContext(high(traceId),
(new BigInteger(traceId, 16)).longValue(),
(new BigInteger(parts[1], 16)).longValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public int getThreadCount() {
@VisibleForTesting
public void runPeriodicalTaskNow() throws Exception {
BackgroundTaskQueue tasks = getTasks();
while (tasks.size() > 0) {
while (!tasks.isEmpty()) {
tasks.poll().call();
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public synchronized void run() {
LOG.debug("Number of background tasks to execute : {}", tasks.size());
}

while (tasks.size() > 0) {
while (!tasks.isEmpty()) {
BackgroundTask task = tasks.poll();
CompletableFuture.runAsync(() -> {
long startTime = System.nanoTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public boolean verifyChecksumDataMatches(ChecksumData that, int startIndex)
throws OzoneChecksumException {

// pre checks
if (this.checksums.size() == 0) {
if (this.checksums.isEmpty()) {
throw new OzoneChecksumException("Original checksumData has no " +
"checksums");
}

if (that.checksums.size() == 0) {
if (that.checksums.isEmpty()) {
throw new OzoneChecksumException("Computed checksumData has no " +
"checksums");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void testChooseRandomExcludedNode(NodeSchema[] schemas,
excludedList, ancestorGen);
for (Node key : dataNodes) {
if (excludedList.contains(key) ||
(ancestorList.size() > 0 &&
(!ancestorList.isEmpty() &&
ancestorList.stream()
.map(a -> (InnerNode) a)
.anyMatch(a -> a.isAncestor(key)))) {
Expand Down Expand Up @@ -558,7 +558,7 @@ void testChooseRandomExcludedNodeAndScope(NodeSchema[] schemas,
excludedList, ancestorGen);
for (Node key : dataNodes) {
if (excludedList.contains(key) || key.isDescendant(path) ||
(ancestorList.size() > 0 &&
(!ancestorList.isEmpty() &&
ancestorList.stream()
.map(a -> (InnerNode) a)
.anyMatch(a -> a.isAncestor(key)))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void checkState(boolean state, String errorString) {
}

public static StorageSize parse(String value) {
checkState(value != null && value.length() > 0, "value cannot be blank");
checkState(value != null && !value.isEmpty(), "value cannot be blank");
String sanitizedValue = value.trim().toLowerCase(Locale.ENGLISH);
StorageUnit parsedUnit = null;
for (StorageUnit unit : StorageUnit.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public boolean isThreadPoolAvailable(ExecutorService executor) {
}

ThreadPoolExecutor ex = (ThreadPoolExecutor) executor;
if (ex.getQueue().size() == 0) {
if (ex.getQueue().isEmpty()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public CommandDispatcher build() {
"Missing scm connection manager.");
Preconditions.checkNotNull(this.container, "Missing ozone container.");
Preconditions.checkNotNull(this.context, "Missing state context.");
Preconditions.checkArgument(this.handlerList.size() > 0,
Preconditions.checkArgument(!this.handlerList.isEmpty(),
"The number of command handlers must be greater than 0.");
return new CommandDispatcher(this.container, this.connectionManager,
this.context, handlerList.toArray(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void checkVolumeSet(MutableVolumeSet volumeSet,
volumeSet.failVolume(volume.getStorageDir().getPath());
}
}
if (volumeSet.getVolumesList().size() == 0) {
if (volumeSet.getVolumesList().isEmpty()) {
// All volumes are in inconsistent state
throw new DiskOutOfSpaceException(
"All configured Volumes are in Inconsistent State");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void initializeVolumeSet() throws IOException {

// First checking if we have any volumes, if all volumes are failed the
// volumeMap size will be zero, and we throw Exception.
if (volumeMap.size() == 0) {
if (volumeMap.isEmpty()) {
throw new DiskOutOfSpaceException("No storage locations configured");
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public void checkAllVolumes(StorageVolumeChecker checker)
throw new IOException("Interrupted while running disk check", e);
}

if (failedVolumes.size() > 0) {
if (!failedVolumes.isEmpty()) {
LOG.warn("checkAllVolumes got {} failed volumes - {}",
failedVolumes.size(), failedVolumes);
handleVolumeFailures(failedVolumes);
Expand Down Expand Up @@ -266,7 +266,7 @@ public void checkVolumeAsync(StorageVolume volume) {

volumeChecker.checkVolume(
volume, (healthyVolumes, failedVolumes) -> {
if (failedVolumes.size() > 0) {
if (!failedVolumes.isEmpty()) {
LOG.warn("checkVolumeAsync callback got {} failed volumes: {}",
failedVolumes.size(), failedVolumes);
} else {
Expand Down Expand Up @@ -441,7 +441,7 @@ public boolean hasEnoughVolumes() {
boolean hasEnoughVolumes;
if (maxVolumeFailuresTolerated ==
StorageVolumeChecker.MAX_VOLUME_FAILURE_TOLERATED_LIMIT) {
hasEnoughVolumes = getVolumesList().size() >= 1;
hasEnoughVolumes = !getVolumesList().isEmpty();
} else {
hasEnoughVolumes = getFailedVolumesList().size() <= maxVolumeFailuresTolerated;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public HddsVolume chooseVolume(List<HddsVolume> volumes,
long maxContainerSize) throws IOException {

// No volumes available to choose from
if (volumes.size() < 1) {
if (volumes.isEmpty()) {
throw new DiskOutOfSpaceException("No more available volumes");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void reconstructECBlockGroup(BlockLocationInfo blockLocationInfo,
emptyBlockStreams[i] = getECBlockOutputStream(blockLocationInfo, datanodeDetails, repConfig, replicaIndex);
}

if (toReconstructIndexes.size() > 0) {
if (!toReconstructIndexes.isEmpty()) {
sis.setRecoveryIndexes(toReconstructIndexes.stream().map(i -> (i - 1))
.collect(Collectors.toSet()));
long length = safeBlockGroupLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void create(VolumeSet volumeSet, VolumeChoosingPolicy
LOG.error("Exception attempting to create container {} on volume {}" +
" remaining volumes to try {}", containerData.getContainerID(),
containerVolume.getHddsRootDir(), volumes.size(), ex);
if (volumes.size() == 0) {
if (volumes.isEmpty()) {
throw new StorageContainerException(
"Container creation failed. " + ex.getMessage(), ex,
CONTAINER_INTERNAL_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private ScanResult scanBlock(BlockData block, DataTransferThrottler throttler,
// In EC, client may write empty putBlock in padding block nodes.
// So, we need to make sure, chunk length > 0, before declaring
// the missing chunk file.
if (block.getChunks().size() > 0 && block
if (!block.getChunks().isEmpty() && block
.getChunks().get(0).getLen() > 0) {
return ScanResult.unhealthy(ScanResult.FailureType.MISSING_CHUNK_FILE,
chunkFile, new IOException("Missing chunk file " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public synchronized List<X509Certificate> getTrustChain()
if (cert != null) {
chain.add(cert);
}
Preconditions.checkState(chain.size() > 0, "Empty trust chain");
Preconditions.checkState(!chain.isEmpty(), "Empty trust chain");
}
return chain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static ManagedDBOptions readFromFile(String dbFileName,
List<ColumnFamilyDescriptor> cfDescs) throws IOException {
Preconditions.checkNotNull(dbFileName);
Preconditions.checkNotNull(cfDescs);
Preconditions.checkArgument(cfDescs.size() > 0);
Preconditions.checkArgument(!cfDescs.isEmpty());

//TODO: Add Documentation on how to support RocksDB Mem Env.
Env env = Env.getDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private ManagedDBOptions getDBOptionsFromFile(
columnFamilyDescriptors.add(tc.getDescriptor());
}

if (columnFamilyDescriptors.size() > 0) {
if (!columnFamilyDescriptors.isEmpty()) {
try {
option = DBConfigFromFile.readFromFile(dbname,
columnFamilyDescriptors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public DBUpdatesWrapper getUpdatesSince(long sequenceNumber, long limitCount)
sequenceNumber, e);
dbUpdatesWrapper.setDBUpdateSuccess(false);
} finally {
if (dbUpdatesWrapper.getData().size() > 0) {
if (!dbUpdatesWrapper.getData().isEmpty()) {
rdbMetrics.incWalUpdateDataSize(cumulativeDBUpdateLogBatchSize);
rdbMetrics.incWalUpdateSequenceCount(
dbUpdatesWrapper.getCurrentSequenceNumber() - sequenceNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ && get(startKey) == null) {
currentKey, null))) {
result.add(currentEntry);
} else {
if (result.size() > 0 && sequential) {
if (!result.isEmpty() && sequential) {
// if the caller asks for a sequential range of results,
// and we met a dis-match, abort iteration from here.
// if result is empty, we continue to look for the first match.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public synchronized StatusAndMessages reportStatus(
assertClientId(upgradeClientID);
List<String> returningMsgs = new ArrayList<>(msgs.size() + 10);
Status status = versionManager.getUpgradeState();
while (msgs.size() > 0) {
while (!msgs.isEmpty()) {
returningMsgs.add(msgs.poll());
}
return new StatusAndMessages(status, returningMsgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static String getLexicographicallyHigherString(String val) {
public static List<Optional<String>> getTestingBounds(
SortedMap<String, Integer> keys) {
Set<String> boundary = new HashSet<>();
if (keys.size() > 0) {
if (!keys.isEmpty()) {
List<String> sortedKeys = new ArrayList<>(keys.keySet());
boundary.add(getLexicographicallyLowerString(keys.firstKey()));
boundary.add(keys.firstKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ private void traverseGraph(
// fist go through fwdGraph to find nodes that don't have successors.
// These nodes will be the top level nodes in reverse graph
Set<CompactionNode> successors = fwdMutableGraph.successors(infileNode);
if (successors.size() == 0) {
if (successors.isEmpty()) {
LOG.debug("No successors. Cumulative keys: {}, total keys: {}",
infileNode.getCumulativeKeysReverseTraversal(),
infileNode.getTotalNumberOfKeys());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected List<DatanodeDetails> chooseDatanodesInternal(
healthyNodes.removeAll(usedNodes);
}
String msg;
if (healthyNodes.size() == 0) {
if (healthyNodes.isEmpty()) {
msg = "No healthy node found to allocate container.";
LOG.error(msg);
throw new SCMException(msg, SCMException.ResultCodes
Expand Down Expand Up @@ -440,7 +440,7 @@ public ContainerPlacementStatus validateContainerPlacement(
// We have a network topology so calculate if it is satisfied or not.
int requiredRacks = getRequiredRackCount(replicas, 0);
if (topology == null || replicas == 1 || requiredRacks == 1) {
if (dns.size() > 0) {
if (!dns.isEmpty()) {
// placement is always satisfied if there is at least one DN.
return validPlacement;
} else {
Expand Down Expand Up @@ -556,7 +556,7 @@ public Set<ContainerReplica> replicasToCopyToFixMisreplication(
.limit(numberOfReplicasToBeCopied)
.collect(Collectors.toList());
if (numberOfReplicasToBeCopied > replicasToBeCopied.size()) {
Node rack = replicaList.size() > 0 ? this.getPlacementGroup(
Node rack = !replicaList.isEmpty() ? this.getPlacementGroup(
replicaList.get(0).getDatanodeDetails()) : null;
LOG.warn("Not enough copyable replicas available in rack {}. " +
"Required number of Replicas to be copied: {}." +
Expand Down Expand Up @@ -641,14 +641,14 @@ public Set<ContainerReplica> replicasToRemoveToFixOverreplication(
Node rack = pq.poll();
Set<ContainerReplica> replicaSet =
placementGroupReplicaIdMap.get(rack).get(rid);
if (replicaSet.size() > 0) {
if (!replicaSet.isEmpty()) {
ContainerReplica r = replicaSet.stream().findFirst().get();
replicasToRemove.add(r);
replicaSet.remove(r);
replicaIdMap.get(rid).remove(r);
placementGroupCntMap.compute(rack,
(group, cnt) -> (cnt == null ? 0 : cnt) - 1);
if (replicaSet.size() == 0) {
if (replicaSet.isEmpty()) {
placementGroupReplicaIdMap.get(rack).remove(rid);
} else {
pq.add(rack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected List<DatanodeDetails> chooseDatanodesInternal(
}
DatanodeDetails favoredNode;
int favorIndex = 0;
if (mutableUsedNodes.size() == 0) {
if (mutableUsedNodes.isEmpty()) {
// choose all nodes for a new pipeline case
// choose first datanode from scope ROOT or from favoredNodes if not null
favoredNode = favoredNodeNum > favorIndex ?
Expand Down
Loading