HADOOP-16345. Fix a potential NPE when instantiating FairCallQueue metrics. Contributed by Erik Krogen.

This commit is contained in:
Erik Krogen 2019-06-07 14:20:44 -07:00
parent 4e38dafde4
commit 76b94c274f

View File

@ -377,9 +377,21 @@ public void setDelegate(FairCallQueue<? extends Schedulable> obj) {
this.revisionNumber++;
}
/**
* Fetch the current call queue from the weak reference delegate. If there
* is no delegate, or the delegate is empty, this will return null.
*/
private FairCallQueue<? extends Schedulable> getCallQueue() {
WeakReference<FairCallQueue<? extends Schedulable>> ref = this.delegate;
if (ref == null) {
return null;
}
return ref.get();
}
@Override
public int[] getQueueSizes() {
FairCallQueue<? extends Schedulable> obj = this.delegate.get();
FairCallQueue<? extends Schedulable> obj = getCallQueue();
if (obj == null) {
return new int[]{};
}
@ -389,7 +401,7 @@ public int[] getQueueSizes() {
@Override
public long[] getOverflowedCalls() {
FairCallQueue<? extends Schedulable> obj = this.delegate.get();
FairCallQueue<? extends Schedulable> obj = getCallQueue();
if (obj == null) {
return new long[]{};
}