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
1 changed files with 14 additions and 2 deletions

View File

@ -377,9 +377,21 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
this.revisionNumber++; 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 @Override
public int[] getQueueSizes() { public int[] getQueueSizes() {
FairCallQueue<? extends Schedulable> obj = this.delegate.get(); FairCallQueue<? extends Schedulable> obj = getCallQueue();
if (obj == null) { if (obj == null) {
return new int[]{}; return new int[]{};
} }
@ -389,7 +401,7 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
@Override @Override
public long[] getOverflowedCalls() { public long[] getOverflowedCalls() {
FairCallQueue<? extends Schedulable> obj = this.delegate.get(); FairCallQueue<? extends Schedulable> obj = getCallQueue();
if (obj == null) { if (obj == null) {
return new long[]{}; return new long[]{};
} }