You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by xk...@apache.org on 2019/06/07 21:32:19 UTC

[hadoop] branch branch-3.2 updated: HADOOP-16345. Fix a potential NPE when instantiating FairCallQueue metrics. Contributed by Erik Krogen.

This is an automated email from the ASF dual-hosted git repository.

xkrogen pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.2 by this push:
     new f607efd  HADOOP-16345. Fix a potential NPE when instantiating FairCallQueue metrics. Contributed by Erik Krogen.
f607efd is described below

commit f607efd1950211f85eb571564b774184f8fa1687
Author: Erik Krogen <ek...@linkedin.com>
AuthorDate: Fri Jun 7 14:20:44 2019 -0700

    HADOOP-16345. Fix a potential NPE when instantiating FairCallQueue metrics. Contributed by Erik Krogen.
    
    (cherry-picked from 76b94c274fe9775efcfd51c676d80c88a4f7fdb9)
---
 .../main/java/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 380426f..b4e9539 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 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[]{};
       }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org