From: Robert Varga Date: Fri, 3 May 2024 21:27:27 +0000 (+0200) Subject: Do not access payload data when not needed X-Git-Tag: v9.0.3~51 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=f98198bfa8ec780cc8197213720cdca13995f4be;p=controller.git Do not access payload data when not needed We are just putting out a debug, make sure to make this operation conditional. Change-Id: I79c39aab6bb6c94efa03e5a878ceabdb552d93cd Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/SimpleReplicatedLogEntrySerializer.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/SimpleReplicatedLogEntrySerializer.java index 250551a780..b0e3c65e56 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/SimpleReplicatedLogEntrySerializer.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/persisted/SimpleReplicatedLogEntrySerializer.java @@ -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; }