ppkarwasz commented on code in PR #3675: URL: https://github.com/apache/logging-log4j2/pull/3675#discussion_r2104350079
########## log4j-api/src/main/java/org/apache/logging/log4j/util/ReadOnlyStringMapUtil.java: ########## @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j.util; + +import java.util.Map; + +/** + * Utility class for ReadOnlyStringMap implementations. Provides methods for equals and hashCode calculations. + * + * @since 2.25.0 + */ +@InternalApi +public final class ReadOnlyStringMapUtil { Review Comment: I'm a bit concerned about introducing a new public class in `log4j-api`, especially since it's primary purpose is to solve a testing problem. While standardizing `ReadOnlyStringMap` behavior has value, doing so in the Log4j API introduces a version dependency: `log4j-core` 2.25.x would no longer be compatible with `log4j-api` 2.24.x. To avoid this incompatibility, what do you think about implementing `equals()` and `hashCode()` directly like this instead? ```java @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof ReadOnlyStringMap) { return toMap().equals(((ReadOnlyStringMap) other).toMap()); } return false; } @Override public int hashCode() { return toMap().hashCode(); } ``` This would preserve compatibility while still ensuring consistent behavior in tests. ########## log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java: ########## @@ -196,6 +193,9 @@ public boolean equals(final Object obj) { if (obj == null) { return false; } + if (obj instanceof ReadOnlyStringMap) { + return ReadOnlyStringMapUtil.equals(this, (ReadOnlyStringMap) obj); + } Review Comment: `DefaultThreadContextMap` is primarily an implementation of `ThreadContextMap`. I am not sure if the fact it implements `ReadOnlyStringMap` is ever used. -- 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: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org