Disable WebSocketInitializer serialization 61/108761/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Oct 2023 22:21:12 +0000 (23:21 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Oct 2023 22:22:12 +0000 (23:22 +0100)
Our servlet cannot be serialized because it has external dependencies.
Disable serialization and eliminate @SuppressFBWarnings annotations.

JIRA: NETCONF-1102
Change-Id: If4d1801745ea34b0704e6e4f8a534b302c1fc770
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/WebSocketInitializer.java

index 97a93e585b3fc1b557c5223e927deee90ad68f8e..206e57cc5f15601697c3f7e2f92bdc752b5b38c6 100644 (file)
@@ -10,8 +10,10 @@ package org.opendaylight.restconf.nb.rfc8040.streams;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.io.Serial;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.concurrent.ScheduledExecutorService;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -31,17 +33,14 @@ import org.slf4j.LoggerFactory;
  */
 @Singleton
 public final class WebSocketInitializer extends WebSocketServlet {
-    @Serial
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
 
-    @SuppressFBWarnings(value = "SE_BAD_FIELD",
-        justification = "Servlet/WebSocket bridge, we need this service for heartbeats")
-    private final ScheduledExecutorService executorService;
+    private final transient ScheduledExecutorService executorService;
+    private final transient ListenersBroker listenersBroker;
     private final int maximumFragmentLength;
     private final int heartbeatInterval;
     private final int idleTimeoutMillis;
-    @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Required for session mgmt")
-    private final ListenersBroker listenersBroker;
 
     /**
      * Creation of the web-socket initializer.
@@ -71,6 +70,22 @@ public final class WebSocketInitializer extends WebSocketServlet {
             heartbeatInterval));
     }
 
+    @java.io.Serial
+    @SuppressWarnings("static-method")
+    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
+        throwNSE();
+    }
+
+    @java.io.Serial
+    @SuppressWarnings("static-method")
+    private void writeObject(final ObjectOutputStream out) throws IOException {
+        throwNSE();
+    }
+
+    private static void throwNSE() throws NotSerializableException {
+        throw new NotSerializableException(WebSocketInitializer.class.getName());
+    }
+
     /**
      * Factory that is used for creation of new web-sockets based on HTTP/HTTPS upgrade request.
      */