Sprinkle @NonNull annotations 69/98369/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Nov 2021 15:50:25 +0000 (16:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Nov 2021 16:17:51 +0000 (17:17 +0100)
We have a few return methods which could use @NonNull annotations,
sprinkle them around.

Change-Id: I48c0f8879127673eb122321dd6c92d4572098f68
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Envelope.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/LocalHistoryIdentifier.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MemberName.java
opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbstractIdentifiablePayload.java

index 8c5f513bbf3807d410774015543b6fd72ebf491d..c6123d6fc35de45a4946dba21ac68f6a6b92dadc 100644 (file)
@@ -11,12 +11,13 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
 import java.io.Serializable;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Immutable;
 
 public abstract class Envelope<T extends Message<?, ?>> implements Immutable, Serializable {
     private static final long serialVersionUID = 1L;
 
-    private final T message;
+    private final @NonNull T message;
     private final long txSequence;
     private final long sessionId;
 
@@ -31,7 +32,7 @@ public abstract class Envelope<T extends Message<?, ?>> implements Immutable, Se
      *
      * @return enclose message
      */
-    public T getMessage() {
+    public @NonNull T getMessage() {
         return message;
     }
 
index d47f03773bdcb048a1e8488aa9f4fd792b817147..10abac6d58236deffc1f6af0f46358b52481be40 100644 (file)
@@ -17,6 +17,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Objects;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.WritableIdentifier;
 
 /**
@@ -69,11 +70,11 @@ public final class FrontendIdentifier implements WritableIdentifier {
         this.memberName = requireNonNull(memberName);
     }
 
-    public static FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
+    public static @NonNull FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
         return new FrontendIdentifier(memberName, clientType);
     }
 
-    public static FrontendIdentifier readFrom(final DataInput in) throws IOException {
+    public static @NonNull FrontendIdentifier readFrom(final DataInput in) throws IOException {
         final MemberName memberName = MemberName.readFrom(in);
         final FrontendType clientType = FrontendType.readFrom(in);
         return new FrontendIdentifier(memberName, clientType);
@@ -85,11 +86,11 @@ public final class FrontendIdentifier implements WritableIdentifier {
         clientType.writeTo(out);
     }
 
-    public FrontendType getClientType() {
+    public @NonNull FrontendType getClientType() {
         return clientType;
     }
 
-    public MemberName getMemberName() {
+    public @NonNull MemberName getMemberName() {
         return memberName;
     }
 
@@ -111,7 +112,7 @@ public final class FrontendIdentifier implements WritableIdentifier {
         return memberName.equals(other.memberName) && clientType.equals(other.clientType);
     }
 
-    public String toPersistentId() {
+    public @NonNull String toPersistentId() {
         return memberName.getName() + "-frontend-" + clientType.getName();
     }
 
index f8f890e2c1df0e75969b2c85fb82b8fd2d93f2aa..137bf5907f3ca985170f482d49ae48d86debbc56 100644 (file)
@@ -16,6 +16,7 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.WritableIdentifier;
 import org.opendaylight.yangtools.concepts.WritableObjects;
 
@@ -51,7 +52,7 @@ public final class LocalHistoryIdentifier implements WritableIdentifier {
         }
 
         Proxy(final ClientIdentifier frontendId, final long historyId, final long cookie) {
-            this.clientId = requireNonNull(frontendId);
+            clientId = requireNonNull(frontendId);
             this.historyId = historyId;
             this.cookie = cookie;
         }
@@ -77,7 +78,7 @@ public final class LocalHistoryIdentifier implements WritableIdentifier {
     }
 
     private static final long serialVersionUID = 1L;
-    private final ClientIdentifier clientId;
+    private final @NonNull ClientIdentifier clientId;
     private final long historyId;
     private final long cookie;
 
@@ -86,12 +87,12 @@ public final class LocalHistoryIdentifier implements WritableIdentifier {
     }
 
     public LocalHistoryIdentifier(final ClientIdentifier frontendId, final long historyId, final long cookie) {
-        this.clientId = requireNonNull(frontendId);
+        clientId = requireNonNull(frontendId);
         this.historyId = historyId;
         this.cookie = cookie;
     }
 
-    public static LocalHistoryIdentifier readFrom(final DataInput in) throws IOException {
+    public static @NonNull LocalHistoryIdentifier readFrom(final DataInput in) throws IOException {
         final ClientIdentifier clientId = ClientIdentifier.readFrom(in);
 
         final byte header = WritableObjects.readLongHeader(in);
@@ -105,7 +106,7 @@ public final class LocalHistoryIdentifier implements WritableIdentifier {
         WritableObjects.writeLongs(out, historyId, cookie);
     }
 
-    public ClientIdentifier getClientId() {
+    public @NonNull ClientIdentifier getClientId() {
         return clientId;
     }
 
index 8a1123da520f9ff74d7a504d6839e0ec0d07be20..3cc2b0c6398ec59bde76877648e40bc7e4e71c27 100644 (file)
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.nio.charset.StandardCharsets;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.WritableIdentifier;
 
 /**
@@ -65,7 +66,8 @@ public final class MemberName implements Comparable<MemberName>, WritableIdentif
     }
 
     private static final long serialVersionUID = 1L;
-    private final String name;
+
+    private final @NonNull String name;
 
     @SuppressFBWarnings(value = "VO_VOLATILE_REFERENCE_TO_ARRAY",
             justification = "The array elements are non-volatile but we don't access them.")
@@ -80,13 +82,13 @@ public final class MemberName implements Comparable<MemberName>, WritableIdentif
         this.serialized = verifyNotNull(serialized);
     }
 
-    public static MemberName forName(final String name) {
+    public static @NonNull MemberName forName(final String name) {
         checkArgument(!Strings.isNullOrEmpty(name));
         // TODO: consider caching instances here
         return new MemberName(name);
     }
 
-    public static MemberName readFrom(final DataInput in) throws IOException {
+    public static @NonNull MemberName readFrom(final DataInput in) throws IOException {
         final byte[] serialized = new byte[in.readInt()];
         in.readFully(serialized);
         return new MemberName(new String(serialized, StandardCharsets.UTF_8));
@@ -99,12 +101,12 @@ public final class MemberName implements Comparable<MemberName>, WritableIdentif
         out.write(local);
     }
 
-    public String getName() {
+    public @NonNull String getName() {
         return name;
     }
 
     public org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.cds.types.rev191024
-        .MemberName toYang() {
+        .@NonNull MemberName toYang() {
         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.cds.types.rev191024
                 .MemberName(name);
     }
index 8fa0b627027166abbf207be2a3f63f2da481f840..d2a92ea1913374a2dfa693195f27f1916938d347 100644 (file)
@@ -62,7 +62,7 @@ public final class TransactionIdentifier implements WritableIdentifier {
     }
 
     private static final long serialVersionUID = 1L;
-    private final LocalHistoryIdentifier historyId;
+    private final @NonNull LocalHistoryIdentifier historyId;
     private final long transactionId;
     private String shortString;
 
@@ -71,7 +71,7 @@ public final class TransactionIdentifier implements WritableIdentifier {
         this.transactionId = transactionId;
     }
 
-    public static TransactionIdentifier readFrom(final DataInput in) throws IOException {
+    public static @NonNull TransactionIdentifier readFrom(final DataInput in) throws IOException {
         final LocalHistoryIdentifier historyId = LocalHistoryIdentifier.readFrom(in);
         return new TransactionIdentifier(historyId, WritableObjects.readLong(in));
     }
@@ -82,7 +82,7 @@ public final class TransactionIdentifier implements WritableIdentifier {
         WritableObjects.writeLong(out, transactionId);
     }
 
-    public LocalHistoryIdentifier getHistoryId() {
+    public @NonNull LocalHistoryIdentifier getHistoryId() {
         return historyId;
     }
 
index 32e155bf03fc50ea89dc0932c25c51797d76af87..de9b0bba8a3acd6668fd8c0c54b7edb4d9998092 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.controller.cluster.datastore.persisted;
 
+import static com.google.common.base.Verify.verifyNotNull;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Verify;
 import com.google.common.io.ByteStreams;
 import java.io.DataInput;
 import java.io.Externalizable;
@@ -32,6 +32,7 @@ public abstract class AbstractIdentifiablePayload<T extends Identifier> extends
         implements Serializable {
     protected abstract static class AbstractProxy<T extends Identifier> implements Externalizable {
         private static final long serialVersionUID = 1L;
+
         private byte[] serialized;
         private T identifier;
 
@@ -54,11 +55,11 @@ public abstract class AbstractIdentifiablePayload<T extends Identifier> extends
             final int length = in.readInt();
             serialized = new byte[length];
             in.readFully(serialized);
-            identifier = Verify.verifyNotNull(readIdentifier(ByteStreams.newDataInput(serialized)));
+            identifier = verifyNotNull(readIdentifier(ByteStreams.newDataInput(serialized)));
         }
 
         protected final Object readResolve() {
-            return Verify.verifyNotNull(createObject(identifier, serialized));
+            return verifyNotNull(createObject(identifier, serialized));
         }
 
         protected abstract @NonNull T readIdentifier(@NonNull DataInput in) throws IOException;
@@ -68,8 +69,9 @@ public abstract class AbstractIdentifiablePayload<T extends Identifier> extends
     }
 
     private static final long serialVersionUID = 1L;
-    private final byte[] serialized;
-    private final T identifier;
+
+    private final byte @NonNull [] serialized;
+    private final @NonNull T identifier;
 
     AbstractIdentifiablePayload(final @NonNull T identifier, final byte @NonNull[] serialized) {
         this.identifier = requireNonNull(identifier);
@@ -87,7 +89,7 @@ public abstract class AbstractIdentifiablePayload<T extends Identifier> extends
     }
 
     protected final Object writeReplace() {
-        return Verify.verifyNotNull(externalizableProxy(serialized));
+        return verifyNotNull(externalizableProxy(serialized));
     }
 
     @SuppressWarnings("checkstyle:hiddenField")