From 2b363e88fcc3af2b329931f780948d31f7a67dba Mon Sep 17 00:00:00 2001 From: Greg Schohn Date: Wed, 25 Sep 2024 14:46:27 -0400 Subject: [PATCH] A couple more assertions and throws in error cases to appease SonarQube's quality rules. Signed-off-by: Greg Schohn --- .../bulkload/version_universal/RemoteReaderClient.java | 8 +++++--- .../migrations/replay/util/ActiveContextMonitor.java | 3 ++- .../migrations/replay/util/OnlineRadixSorter.java | 10 ++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/version_universal/RemoteReaderClient.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/version_universal/RemoteReaderClient.java index a0be6f10d..06b08a495 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/version_universal/RemoteReaderClient.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/version_universal/RemoteReaderClient.java @@ -10,6 +10,7 @@ import org.opensearch.migrations.bulkload.common.http.ConnectionContext; import org.opensearch.migrations.bulkload.common.http.HttpResponse; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -40,7 +41,8 @@ public ObjectNode getClusterData() { ) .collectMap(Entry::getKey, Entry::getValue) .block(); - + + assert responses != null; var globalMetadata = globalMetadataFromParts(responses); log.atDebug() .setMessage("Combined global metadata:\n{}") @@ -49,11 +51,11 @@ public ObjectNode getClusterData() { return globalMetadata; } - private ObjectNode globalMetadataFromParts(Map templatesDetails) { + private ObjectNode globalMetadataFromParts(@NonNull Map templatesDetails) { var rootNode = objectMapper.createObjectNode(); templatesDetails.forEach((name, json) -> { - if (json != null && json.size() != 0) { + if (json != null && !json.isEmpty()) { var inner = objectMapper.createObjectNode().set(name, json); rootNode.set(name, inner); } diff --git a/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/ActiveContextMonitor.java b/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/ActiveContextMonitor.java index e137f66be..98ceda5dc 100644 --- a/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/ActiveContextMonitor.java +++ b/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/ActiveContextMonitor.java @@ -382,7 +382,8 @@ private Optional logActiveItems( } if (numOutput++ == 0) { logger.accept( - getHigherLevel(levelForElementOp, Optional.of(Level.INFO)).get(), + getHigherLevel(levelForElementOp, Optional.of(Level.INFO)) + .orElseThrow(IllegalStateException::new), () -> "Oldest of " + totalItems + trailingGroupLabel ); } diff --git a/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/OnlineRadixSorter.java b/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/OnlineRadixSorter.java index 5bdcf397d..a6eaafc57 100644 --- a/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/OnlineRadixSorter.java +++ b/TrafficCapture/trafficReplayer/src/main/java/org/opensearch/migrations/replay/util/OnlineRadixSorter.java @@ -81,10 +81,10 @@ public TrackedFuture addFutureForWork(final int index, FutureTran "index (" + index + ")" + " must be > last processed item (" + currentOffset + ")" ); } - for (int nextKey = Math.max( - currentOffset, - items.isEmpty() ? Integer.MIN_VALUE : items.lastKey() + 1 - ); nextKey <= index; ++nextKey) { + for (int nextKey = Math.max(currentOffset, items.isEmpty() ? Integer.MIN_VALUE : items.lastKey() + 1); + nextKey <= index; + ++nextKey) + { int finalNextKey = nextKey; var signalFuture = items.isEmpty() ? new TextTrackedFuture( @@ -108,6 +108,8 @@ public TrackedFuture addFutureForWork(final int index, FutureTran }, () -> "cleaning up spent work for idx #" + finalNextKey); items.put(nextKey, workItem); } + assert workItem != null : "workItem wasn't set and the earlier checks didn't signal " + + "why there might have been an issue idx=" + index + " this=" + this; } return workItem.addWorkFuture(processor, index); }