Annotate mdsal-binding-api with @NonNull 40/76740/8
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Oct 2018 10:48:57 +0000 (12:48 +0200)
committerJie Han <han.jie@zte.com.cn>
Tue, 9 Oct 2018 01:44:33 +0000 (01:44 +0000)
This fixes a mismatch with mdsal-binding-util and formalizes
existing effective contracts.

JIRA: MDSAL-373
Change-Id: I98914a04fb0efb8f5ebd70058f39f9fb36bdf5b9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
15 files changed:
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/CursorAwareWriteTransaction.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataBroker.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataObjectModification.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeCommitCohort.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeCommitCohortRegistry.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeIdentifier.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeWriteCursor.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/MountPoint.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/NotificationPublishService.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/NotificationService.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/ReadOperations.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/RpcConsumerRegistry.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/TransactionChainListener.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/TransactionFactory.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/WriteOperations.java

index 46d5c5d4278c2836736706ddd1899c8dadd2ee4e..fd2585812786af94a85e0f845368fddd9bdc90e3 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.mdsal.binding.api;
 
 import com.google.common.util.concurrent.FluentFuture;
+import javax.annotation.CheckReturnValue;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
@@ -72,5 +73,6 @@ public interface CursorAwareWriteTransaction extends DataTreeCursorProvider {
      *         operation is complete. A successful commit returns nothing. On failure, the Future will fail with a
      *         {@link TransactionCommitFailedException} or an exception derived from TransactionCommitFailedException.
      */
-    FluentFuture<? extends @NonNull CommitInfo> commit();
+    @CheckReturnValue
+    @NonNull FluentFuture<? extends @NonNull CommitInfo> commit();
 }
index 16e271712328e95a1dfd15244ee1a55c8152b9fd..39a984fbe0d97325ef606023296cfc53ae20e7d0 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Provides access to a conceptual data tree store and also provides the ability to
  * subscribe for changes to data under a given branch of the tree.
@@ -46,5 +48,5 @@ public interface DataBroker extends BindingService, TransactionFactory, DataTree
      * @param listener Transaction chain event listener
      * @return A new transaction chain.
      */
-    TransactionChain createTransactionChain(TransactionChainListener listener);
+    @NonNull TransactionChain createTransactionChain(@NonNull TransactionChainListener listener);
 }
index 1236bc8cdefbaf9f9c524cb955a398a5c60ebfe6..ed4729059bd6db61371b67ead56a5eb53e82d77b 100644 (file)
@@ -163,7 +163,7 @@ public interface DataObjectModification<T extends DataObject> extends
      * @throws IllegalArgumentException If supplied {@code listItem} class is not valid child according
      *         to generated model.
      */
-    <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> DataObjectModification<N>
+    <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> @Nullable DataObjectModification<N>
             getModifiedChildListItem(@NonNull Class<N> listItem, @NonNull K listKey);
 
     /**
index abc8aa84b8de3988bafefa5d6cdd5934af52dbfb..e0e07ad46523ff8b3d9fb954a32fe4cce5405ac5 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.mdsal.binding.api;
 import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.Collection;
+import javax.annotation.CheckReturnValue;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.DataValidationFailedException;
 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
@@ -100,6 +101,7 @@ public interface DataTreeCommitCohort<T extends DataObject> {
      *         more specific subclasses of this exception to provide additional information about
      *         validation failure reason.
      */
-    FluentFuture<PostCanCommitStep> canCommit(@NonNull Object txId,
+    @CheckReturnValue
+    @NonNull FluentFuture<PostCanCommitStep> canCommit(@NonNull Object txId,
             @NonNull Collection<DataTreeModification<T>> modifications);
 }
index ec30a938e78ac931669e583ce73966063758fd74..811ed33bfc6692126c0de15cd088fbdbbfd087a3 100644 (file)
@@ -5,9 +5,9 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.mdsal.binding.api;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
@@ -18,10 +18,8 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
  * See {@link DataTreeCommitCohort} for more details.
  *
  * @author Tony Tkacik &lt;ttkacik@cisco.com&gt;
- *
  */
 public interface DataTreeCommitCohortRegistry {
-
     /**
      * Register commit cohort which will participate in three-phase commit protocols of write
      * transaction in data broker associated with this instance of extension.
@@ -30,7 +28,6 @@ public interface DataTreeCommitCohortRegistry {
      * @param cohort Commit cohort
      * @return Registaration object for DOM Data Three Commit cohort.
      */
-    <D extends DataObject, T extends DataTreeCommitCohort<D>> ObjectRegistration<T> registerCommitCohort(
-            DataTreeIdentifier<D> subtree, T cohort);
-
+    <D extends DataObject, T extends DataTreeCommitCohort<D>> @NonNull ObjectRegistration<T> registerCommitCohort(
+            @NonNull DataTreeIdentifier<D> subtree, @NonNull T cohort);
 }
index c8eaaad3c1e07afbea8b0a7fa2187c7c4a8aa641..89c72c53616b6dea7e60f7dddc12818db87a8e72 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
 import java.io.Serializable;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -24,16 +25,18 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 public final class DataTreeIdentifier<T extends DataObject> implements Immutable,
         Path<DataTreeIdentifier<?>>, Serializable {
     private static final long serialVersionUID = 1L;
-    private final InstanceIdentifier<T> rootIdentifier;
-    private final LogicalDatastoreType datastoreType;
 
-    private DataTreeIdentifier(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> rootIdentifier) {
-        this.datastoreType = Preconditions.checkNotNull(datastoreType);
-        this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
+    private final @NonNull InstanceIdentifier<T> rootIdentifier;
+    private final @NonNull LogicalDatastoreType datastoreType;
+
+    private DataTreeIdentifier(final @NonNull LogicalDatastoreType datastoreType,
+            final @NonNull InstanceIdentifier<T> rootIdentifier) {
+        this.datastoreType = requireNonNull(datastoreType);
+        this.rootIdentifier = requireNonNull(rootIdentifier);
     }
 
-    public static <T extends DataObject> DataTreeIdentifier<T> create(final LogicalDatastoreType datastoreType,
-            final InstanceIdentifier<T> rootIdentifier) {
+    public static <T extends DataObject> @NonNull DataTreeIdentifier<T> create(
+            final @NonNull LogicalDatastoreType datastoreType, final @NonNull InstanceIdentifier<T> rootIdentifier) {
         return new DataTreeIdentifier<>(datastoreType, rootIdentifier);
     }
 
index a2e7b5b4d4f21a43594f15a9108420d4042d2af7..090e2b7084edf3c2ccd84e171beab635a6119449 100644 (file)
@@ -5,9 +5,9 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.mdsal.binding.api;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.BackendFailedException;
@@ -19,7 +19,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.BackendFailedExcepti
  * In addition this cursor also provides write operations(delete, merge, write).
  */
 public interface DataTreeWriteCursor extends DataTreeCursor {
-
     /**
      * Delete the specified child.
      *
@@ -27,7 +26,7 @@ public interface DataTreeWriteCursor extends DataTreeCursor {
      * @throws BackendFailedException when implementation-specific errors occurs while servicing the
      *         request.
      */
-    void delete(PathArgument child);
+    void delete(@NonNull PathArgument child);
 
     /**
      * Merge the specified data with the currently-present data at specified path.
@@ -37,7 +36,7 @@ public interface DataTreeWriteCursor extends DataTreeCursor {
      * @throws BackendFailedException when implementation-specific errors occurs while servicing the
      *         request.
      */
-    <T extends DataObject> void merge(PathArgument child, T data);
+    <T extends DataObject> void merge(@NonNull PathArgument child, @NonNull T data);
 
     /**
      * Replace the data at specified path with supplied data.
@@ -47,5 +46,5 @@ public interface DataTreeWriteCursor extends DataTreeCursor {
      * @throws BackendFailedException when implementation-specific errors occurs while servicing the
      *         request.
      */
-    <T extends DataObject> void write(PathArgument child, T data);
+    <T extends DataObject> void write(@NonNull PathArgument child, @NonNull T data);
 }
index f50a5e984b727b27c2cb789d5fb70ca766f9f88b..28ec05ff2336ee7532c882ac2f698e059c88494e 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.mdsal.binding.api;
 
 import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public interface MountPoint extends Identifiable<InstanceIdentifier<?>> {
 
-    <T extends BindingService> Optional<T> getService(Class<T> service);
-
+    <T extends BindingService> @NonNull Optional<T> getService(@NonNull Class<T> service);
 }
index 1541008f3c84ccd330642198644b4fa214357c8c..1fe34a0011961f6a720dcb8691071ec42067e41a 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
-import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.TimeUnit;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 /**
@@ -23,7 +24,7 @@ import org.opendaylight.yangtools.yang.binding.Notification;
  * - {@link #offerNotification(Notification, int, TimeUnit)}, which may block
  *   for specified time if resources are thin.
  *
- *<p>
+ * <p>
  * The actual delivery to listeners is asynchronous and implementation-specific.
  * Users of this interface should not make any assumptions as to whether the
  * notification has or has not been seen.
@@ -34,7 +35,7 @@ public interface NotificationPublishService extends BindingService {
      * Well-known value indicating that the binding-aware implementation is currently not
      * able to accept a notification.
      */
-    ListenableFuture<Object> REJECTED = Futures.immediateFailedFuture(
+    ListenableFuture<Object> REJECTED = FluentFutures.immediateFailedFluentFuture(
             new NotificationRejectedException("Rejected due to resource constraints."));
 
     /**
@@ -50,7 +51,7 @@ public interface NotificationPublishService extends BindingService {
      * @throws InterruptedException if interrupted while waiting
      * @throws NullPointerException if the notification is null
      */
-    void putNotification(Notification notification) throws InterruptedException;
+    void putNotification(@NonNull Notification notification) throws InterruptedException;
 
     /**
      * Publishes a notification to subscribed listeners. This initiates the process of sending the
@@ -66,7 +67,7 @@ public interface NotificationPublishService extends BindingService {
      *         resource constraints prevent
      * @throws NullPointerException if the notification is null
      */
-    ListenableFuture<? extends Object> offerNotification(Notification notification);
+    @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification notification);
 
     /**
      * Publishes a notification to subscribed listeners. This initiates the process of sending the
@@ -84,7 +85,6 @@ public interface NotificationPublishService extends BindingService {
      * @throws NullPointerException if the notification or unit is null
      * @throws IllegalArgumentException if timeout is negative.
      */
-    ListenableFuture<? extends Object> offerNotification(Notification notification, int timeout, TimeUnit unit)
-            throws InterruptedException;
-
+    @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification notification,
+            int timeout, @NonNull TimeUnit unit) throws InterruptedException;
 }
index 42729f651254ffaa3d4cb7964b8e15b018994534..8d49fb5e5db3f074c0340ed8b537b5b98fc337e4 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
 
@@ -92,5 +93,5 @@ public interface NotificationService extends BindingService {
      * @return a {@link ListenerRegistration} instance that should be used to unregister the listener
      *         by invoking the {@link ListenerRegistration#close()} method when no longer needed.
      */
-    <T extends NotificationListener> ListenerRegistration<T> registerNotificationListener(T listener);
+    <T extends NotificationListener> @NonNull ListenerRegistration<T> registerNotificationListener(@NonNull T listener);
 }
index ff93bac36bf1d90a33298e1816e7b91cfd381083..57afb7298842a9b7cebcc579abbed5dab0585740 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.mdsal.binding.api;
 
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.ReadFailedException;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -37,6 +38,8 @@ public interface ReadOperations {
      *         <li>If the read of the data fails, the Future will fail with a {@link ReadFailedException} or
      *         an exception derived from ReadFailedException.</li>
      *         </ul>
+     * @throws NullPointerException if any of the arguments is null
      */
-    <T extends DataObject> FluentFuture<Optional<T>> read(LogicalDatastoreType store, InstanceIdentifier<T> path);
+    <T extends DataObject> @NonNull FluentFuture<Optional<T>> read(@NonNull LogicalDatastoreType store,
+            @NonNull InstanceIdentifier<T> path);
 }
index 646cd9a274bdec72c4e9b751c2ee0df40da6ad7e..10c13cf19d793a61ad9c3a8d242a8816bf0e236e 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 
 /**
@@ -69,5 +70,5 @@ public interface RpcConsumerRegistry extends BindingService {
      *        generated from a YANG model.
      * @return the proxy for the requested RPC service. This method never returns null.
      */
-    <T extends RpcService> T getRpcService(Class<T> serviceInterface);
+    <T extends RpcService> @NonNull T getRpcService(@NonNull Class<T> serviceInterface);
 }
index 515dcb75ae78ba3fcf978385b043de183e46d1b5..f88f6d6c18be39e35525424f7cadbae176886611 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.mdsal.binding.api;
 
 import java.util.EventListener;
+import org.eclipse.jdt.annotation.NonNull;
 
 /**
  * Listener for transaction chain events.
@@ -24,7 +25,8 @@ public interface TransactionChainListener extends EventListener {
      * @param transaction Transaction which caused the chain to fail
      * @param cause The cause of transaction failure
      */
-    void onTransactionChainFailed(TransactionChain chain, Transaction transaction, Throwable cause);
+    void onTransactionChainFailed(@NonNull TransactionChain chain, @NonNull Transaction transaction,
+            @NonNull Throwable cause);
 
     /**
      * Invoked when a transaction chain is completed. A transaction chain is considered completed when it has been
@@ -32,6 +34,6 @@ public interface TransactionChainListener extends EventListener {
      *
      * @param chain Transaction chain which completed
      */
-    void onTransactionChainSuccessful(TransactionChain chain);
+    void onTransactionChainSuccessful(@NonNull TransactionChain chain);
 }
 
index f7314bbd26f601c39b48f17701f7275447fb078c..be2eeb0943a2a80458e4e88d467dc09f9d7c8c8c 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * A factory which allocates new transactions to operate on the data tree.
  *
@@ -54,7 +56,7 @@ public interface TransactionFactory {
      *
      * @return A new read-only transaction
      */
-    ReadTransaction newReadOnlyTransaction();
+    @NonNull ReadTransaction newReadOnlyTransaction();
 
     /**
      * Allocates new read-write transaction which provides a mutable view of the data tree.
@@ -67,7 +69,7 @@ public interface TransactionFactory {
      *
      * @return new read-write transaction
      */
-    ReadWriteTransaction newReadWriteTransaction();
+    @NonNull ReadWriteTransaction newReadWriteTransaction();
 
     /**
      * Allocates new write-only transaction based on latest state of data tree.
@@ -88,5 +90,5 @@ public interface TransactionFactory {
      *
      * @return new write-only transaction
      */
-    WriteTransaction newWriteOnlyTransaction();
+    @NonNull WriteTransaction newWriteOnlyTransaction();
 }
index 21cbdeb55d4a4213b15b94853b4271797e9dfb56..2bc0be80625a18e8aa1bfe404c89c0e740b31ca6 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -35,7 +36,8 @@ public interface WriteOperations {
      * @throws IllegalStateException if the transaction has already been submitted
      * @throws NullPointerException if any of the arguments is null
      */
-    <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
+    <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
+            @NonNull T data);
 
     /**
      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole
@@ -57,8 +59,8 @@ public interface WriteOperations {
      * @throws IllegalStateException if the transaction has already been submitted
      * @throws NullPointerException if any of the arguments is null
      */
-    <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
-            boolean createMissingParents);
+    <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
+            @NonNull T data, boolean createMissingParents);
 
     /**
      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
@@ -77,7 +79,8 @@ public interface WriteOperations {
      * @throws IllegalStateException if the transaction has already been submitted
      * @throws NullPointerException if any of the arguments is null
      */
-    <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
+    <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
+            @NonNull T data);
 
     /**
      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
@@ -94,8 +97,8 @@ public interface WriteOperations {
      * @throws IllegalStateException if the transaction has already been submitted
      * @throws NullPointerException if any of the arguments is null
      */
-    <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
-            boolean createMissingParents);
+    <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
+            @NonNull T data, boolean createMissingParents);
 
     /**
      * Removes a piece of data from specified path. This operation does not fail if the specified path does not exist.
@@ -104,7 +107,7 @@ public interface WriteOperations {
      * @param path Data object path
      * @throws IllegalStateException if the transaction was committed or canceled.
      */
-    void delete(LogicalDatastoreType store, InstanceIdentifier<?> path);
+    void delete(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<?> path);
 
     /**
      * Flag value indicating that missing parents should be created.