Skip to content

Commit 76b94c2

Browse files
committed
HADOOP-16345. Fix a potential NPE when instantiating FairCallQueue metrics. Contributed by Erik Krogen.
1 parent 4e38daf commit 76b94c2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,21 @@ public void setDelegate(FairCallQueue<? extends Schedulable> obj) {
377377
this.revisionNumber++;
378378
}
379379

380+
/**
381+
* Fetch the current call queue from the weak reference delegate. If there
382+
* is no delegate, or the delegate is empty, this will return null.
383+
*/
384+
private FairCallQueue<? extends Schedulable> getCallQueue() {
385+
WeakReference<FairCallQueue<? extends Schedulable>> ref = this.delegate;
386+
if (ref == null) {
387+
return null;
388+
}
389+
return ref.get();
390+
}
391+
380392
@Override
381393
public int[] getQueueSizes() {
382-
FairCallQueue<? extends Schedulable> obj = this.delegate.get();
394+
FairCallQueue<? extends Schedulable> obj = getCallQueue();
383395
if (obj == null) {
384396
return new int[]{};
385397
}
@@ -389,7 +401,7 @@ public int[] getQueueSizes() {
389401

390402
@Override
391403
public long[] getOverflowedCalls() {
392-
FairCallQueue<? extends Schedulable> obj = this.delegate.get();
404+
FairCallQueue<? extends Schedulable> obj = getCallQueue();
393405
if (obj == null) {
394406
return new long[]{};
395407
}

0 commit comments

Comments
 (0)