ppkarwasz commented on code in PR #1961:
URL: https://github.com/apache/logging-log4j2/pull/1961#discussion_r1391053385


##########
log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java:
##########
@@ -89,17 +90,24 @@ public Object[] getParameters() {
     }
 
     @Override
+    @SuppressWarnings("UndefinedEquals")
     public boolean equals(final Object o) {
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
+        if (!(o instanceof SimpleMessage)) {
             return false;
         }
 
         final SimpleMessage that = (SimpleMessage) o;
 
-        return !(charSequence != null ? 
!charSequence.equals(that.charSequence) : that.charSequence != null);
+        /*
+         * https://errorprone.info/bugpattern/UndefinedEquals
+         *
+         * If the char sequences are different, we fall back on string 
comparison.
+         */
+        return Objects.equals(this.charSequence, that.charSequence)
+                || Objects.equals(this.getFormattedMessage(), 
that.getFormattedMessage());

Review Comment:
   This change makes the `equals` method more useful: two objects are equal if 
they have the same message.
   
   However it has the side-effect of evaluating `charSequence.toString()`. 
@jvz, what do you think?



-- 
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