From 76b94c274fe9775efcfd51c676d80c88a4f7fdb9 Mon Sep 17 00:00:00 2001 From: Erik Krogen Date: Fri, 7 Jun 2019 14:20:44 -0700 Subject: [PATCH] HADOOP-16345. Fix a potential NPE when instantiating FairCallQueue metrics. Contributed by Erik Krogen. --- .../org/apache/hadoop/ipc/FairCallQueue.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java index 380426fe5b..b4e953948c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java @@ -377,9 +377,21 @@ public void setDelegate(FairCallQueue 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 getCallQueue() { + WeakReference> ref = this.delegate; + if (ref == null) { + return null; + } + return ref.get(); + } + @Override public int[] getQueueSizes() { - FairCallQueue obj = this.delegate.get(); + FairCallQueue obj = getCallQueue(); if (obj == null) { return new int[]{}; } @@ -389,7 +401,7 @@ public int[] getQueueSizes() { @Override public long[] getOverflowedCalls() { - FairCallQueue obj = this.delegate.get(); + FairCallQueue obj = getCallQueue(); if (obj == null) { return new long[]{}; }