jvz commented on code in PR #1961:
URL: https://github.com/apache/logging-log4j2/pull/1961#discussion_r1391516114
##########
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:
How often are messages checked for equality? If it's not a hot path, then I
say go for it. `CharSequence::compare` appears to be a Java 11 method, so
there's no standard way to compare two char sequences apparently.
--
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]