ramanathan1504 commented on code in PR #4271:
URL: https://github.com/apache/logging-log4j2/pull/4271#discussion_r3951720983


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java:
##########
@@ -1341,18 +1338,17 @@ private static StringMap memento(final 
ReadOnlyStringMap data) {
             return result;
         }
 
-        private static MarshalledObject<Message> marshall(final Message msg) {
-            try {
-                return new MarshalledObject<>(msg);
-            } catch (final Exception ex) {
-                return null;
-            }
-        }
-
         private void writeObject(final java.io.ObjectOutputStream s) throws 
IOException {
             this.messageString = message.getFormattedMessage();
-            this.marshalledMessage = marshall(message);
             s.defaultWriteObject();
+            SerializationUtil.writeWrappedObject(message, s);

Review Comment:
   writeWrappedObject serializes into a ByteArrayOutputStream and touches s 
only in its last statement. So a failed attempt leaves s untouched and a 
fallback write is still well formed.
   
   
   ```java
   try {
       SerializationUtil.writeWrappedObject(message, s);
   } catch (final Exception ex) {
       SerializationUtil.writeWrappedObject(new SimpleMessage(messageString), 
s);
   }
   ```
   
     `messageString` is set two lines above and `message()` already prefers 
`message` over it, so the reader needs no change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to