Do not access payload data when not needed 98/111598/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 3 May 2024 21:27:27 +0000 (23:27 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 3 May 2024 22:08:44 +0000 (00:08 +0200)
We are just putting out a debug, make sure to make this operation
conditional.

Change-Id: I79c39aab6bb6c94efa03e5a878ceabdb552d93cd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/SimpleReplicatedLogEntrySerializer.java

index 250551a780d0a5842e409f2b59315f8d63b27191..b0e3c65e56482496869c45990e9f2fe5faa3f557 100644 (file)
@@ -51,12 +51,15 @@ public class SimpleReplicatedLogEntrySerializer extends JSerializer {
 
         final int estimatedSerializedSize = replicatedLogEntry.serializedSize();
 
-        final ByteArrayOutputStream bos = new ByteArrayOutputStream(estimatedSerializedSize);
-        SerializationUtils.serialize(replicatedLogEntry, bos);
-        final byte[] bytes = bos.toByteArray();
+        final var baos = new ByteArrayOutputStream(estimatedSerializedSize);
+        SerializationUtils.serialize(replicatedLogEntry, baos);
+        final byte[] bytes = baos.toByteArray();
 
-        LOG.debug("Estimated serialized size {}, data size {} for payload: {}. Actual serialized size: {}",
-            estimatedSerializedSize, replicatedLogEntry.getData().size(), replicatedLogEntry.getData(), bytes.length);
+        if (LOG.isDebugEnabled()) {
+            final var data = replicatedLogEntry.getData();
+            LOG.debug("Estimated serialized size {}, data size {} for payload: {}. Actual serialized size: {}",
+                estimatedSerializedSize, data.size(), data, bytes.length);
+        }
 
         return bytes;
     }