Skip to content

Commit

Permalink
Avoid out of bounds list indices by ensuring that we always use min(l…
Browse files Browse the repository at this point in the history
…ist.size(), limit.orElse(...))
  • Loading branch information
Miles-Garnsey committed Jan 13, 2023
1 parent def2799 commit 86c1626
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
import systems.composable.dropwizard.cassandra.pooling.PoolingOptionsFactory;
import systems.composable.dropwizard.cassandra.retry.RetryPolicyFactory;

import static java.lang.Math.min;

public final class CassandraStorage implements IStorage, IDistributedStorage {

private static final int METRICS_PARTITIONING_TIME_MINS = 10;
Expand Down Expand Up @@ -985,7 +987,7 @@ public List<RepairRun> getRepairRunsForClusterPrioritiseRunning(String clusterNa
row -> flattenedUuids.add(row.getUUID("id"))
);
}
flattenedUuids.subList(0, limit.orElse(MAX_RETURNED_REPAIR_RUNS));
flattenedUuids.subList(0, min(flattenedUuids.size(), limit.orElse(MAX_RETURNED_REPAIR_RUNS))+1);
// Run an async query on each UUID in the flattened list, against the main repair_run table with
// all columns required as an input to `buildRepairRunFromRow`.
List<ResultSetFuture> repairRunFutures = Lists.<ResultSetFuture>newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.Math.min;

/**
* Implements the StorageAPI using transient Java classes.
*/
Expand Down Expand Up @@ -209,7 +211,7 @@ public int compare(RepairRun o1, RepairRun o2) {
}
};
Collections.sort(foundRepairRuns, comparator);
return foundRepairRuns.subList(0, limit.orElse(1000));
return foundRepairRuns.subList(0, min(foundRepairRuns.size(), limit.orElse(1000))+1);
}

@Override
Expand Down

0 comments on commit 86c1626

Please sign in to comment.