HADOOP-16345. Fix a potential NPE when instantiating FairCallQueue metrics. Contributed by Erik Krogen.
This commit is contained in:
parent
4e38dafde4
commit
76b94c274f
|
@ -377,9 +377,21 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
|
|||
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 class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
|
|||
|
||||
@Override
|
||||
public long[] getOverflowedCalls() {
|
||||
FairCallQueue<? extends Schedulable> obj = this.delegate.get();
|
||||
FairCallQueue<? extends Schedulable> obj = getCallQueue();
|
||||
if (obj == null) {
|
||||
return new long[]{};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue