Bump upstreams
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / messages / RpcResponse.java
index 02d0f1f185116ce30ce0d46754ff26aefe4dd86f..bb308203ddd789fcf783c7ab6e8e0abadd2ca63a 100644 (file)
@@ -7,33 +7,39 @@
  */
 package org.opendaylight.controller.remote.rpc.messages;
 
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.Externalizable;
+import java.io.IOException;
+import java.io.InvalidObjectException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.io.Serializable;
+import java.util.Optional;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
-public class RpcResponse implements Serializable {
+public class RpcResponse extends AbstractResponse<ContainerNode> {
     private static final long serialVersionUID = -4211279498688989245L;
 
-    @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
-            + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
-            + "aren't serialized. FindBugs does not recognize this.")
-    private final NormalizedNode<?, ?> resultNormalizedNode;
-
-    public RpcResponse(final @Nullable NormalizedNode<?, ?> inputNormalizedNode) {
-        resultNormalizedNode = inputNormalizedNode;
+    public RpcResponse(final @Nullable ContainerNode output) {
+        super(output);
     }
 
-    public @Nullable NormalizedNode<?, ?> getResultNormalizedNode() {
-        return resultNormalizedNode;
+    @Override
+    Object writeReplace() {
+        return new Proxy(this);
     }
 
-    private Object writeReplace() {
-        return new Proxy(this);
+    static @Nullable ContainerNode unmaskContainer(final Optional<NormalizedNode> optNode)
+            throws InvalidObjectException {
+        if (optNode.isEmpty()) {
+            return null;
+        }
+        final var node = optNode.orElseThrow();
+        if (node instanceof ContainerNode container) {
+            return container;
+        }
+        throw new InvalidObjectException("Unexpected data " + node.contract().getSimpleName());
     }
 
     private static class Proxy implements Externalizable {
@@ -47,18 +53,18 @@ public class RpcResponse implements Serializable {
         public Proxy() {
         }
 
-        Proxy(RpcResponse rpcResponse) {
+        Proxy(final RpcResponse rpcResponse) {
             this.rpcResponse = rpcResponse;
         }
 
         @Override
-        public void writeExternal(ObjectOutput out) {
-            SerializationUtils.serializeNormalizedNode(rpcResponse.getResultNormalizedNode(), out);
+        public void writeExternal(final ObjectOutput out) throws IOException {
+            SerializationUtils.writeNormalizedNode(out, rpcResponse.getOutput());
         }
 
         @Override
-        public void readExternal(ObjectInput in) {
-            rpcResponse = new RpcResponse(SerializationUtils.deserializeNormalizedNode(in));
+        public void readExternal(final ObjectInput in) throws IOException {
+            rpcResponse = new RpcResponse(unmaskContainer(SerializationUtils.readNormalizedNode(in)));
         }
 
         private Object readResolve() {