dlmarion commented on code in PR #4079:
URL: https://github.com/apache/accumulo/pull/4079#discussion_r1427955608
##########
server/manager/src/main/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueue.java:
##########
@@ -158,7 +159,11 @@ public synchronized long getQueuedJobs() {
}
public synchronized long getLowestPriority() {
- return jobQueue.lastKey().job.getPriority();
+ CompactionJobPriorityQueue.CjpqKey highestJob = null;
+ try {
+ highestJob = jobQueue.lastKey();
+ } catch (NoSuchElementException e) {}
+ return highestJob == null ? 0 : highestJob.job.getPriority();
Review Comment:
If you get a `NoSuchElementException` here, then `highestJob` will always be
`null`. I think you can rewrite this as:
```
try {
return jobQueue.lastKey().job.getPriority();
} catch (NoSuchElementException e) {
return 0;
}
```
The suggestion above relies on an Exception being raised, which is
expensive. Another alternative would be:
```
if (jobQueue.isEmpty()) {
return 0;
}
return jobQueue.lastKey().job.getPriority();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]