From 99c2b121c8c4970c868de6342aac873da29b4ecb Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Fri, 14 Apr 2017 09:50:24 -0400 Subject: [PATCH] Fix FindBugs error in DelayedListenerRegistration#getInstance The ObjectRegistration interface was recently changed to annotate getInstance with @Nonnull to promise it will not return a null. However DelayedListenerRegistration could return null if the delegate is not set yet. In reality, we do not and should not ever call this method on DelayedListenerRegistration instances so I changed it to throw UnsupportedOperationException to make it explicit and to avoid the FindBugs error. Change-Id: I9fe374b23336d8ade65b2f1b697d93f50a090df9 Signed-off-by: Tom Pantelis --- .../cluster/datastore/DelayedListenerRegistration.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java index ac132721c5..8d73bc6155 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DelayedListenerRegistration.java @@ -39,8 +39,13 @@ abstract class DelayedListenerRegistration implement @Override public L getInstance() { - final ListenerRegistration d = delegate; - return d == null ? null : (L)d.getInstance(); + // ObjectRegistration annotates this method as @Nonnull but we could return null if the delegate is not set yet. + // In reality, we do not and should not ever call this method on DelayedListenerRegistration instances anyway + // but, since we have to provide an implementation to satisfy the interface, we throw + // UnsupportedOperationException to honor the API contract of not returning null and to avoid a FindBugs error + // for possibly returning null. + throw new UnsupportedOperationException( + "getInstance should not be called on this instance since it could be null"); } @Override -- 2.36.6