You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "rschmitt (via GitHub)" <gi...@apache.org> on 2025/05/19 17:49:21 UTC
[PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
rschmitt opened a new pull request, #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675
This change rewrites the `equals` and `hashCode` implementations in `SortedArrayStringMap` and `JdkMapAdapterStringMap` to support value-based equality between the two implementations.
Fixes #3669.
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "rschmitt (via GitHub)" <gi...@apache.org>.
rschmitt commented on PR #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675#issuecomment-2898961509
What should I do about these baseline failures?
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675#issuecomment-2891910253
<table>
<tr>
<th>Job</th>
<th>Requested goals</th>
<th>Build Tool Version</th>
<th>Build Outcome</th>
<th>Build ScanĀ®</th>
</tr>
<tr>
<td>build-macos-latest</td>
<td>clean install</td>
<td align='center'>3.9.8</td>
<td align='center'>:white_check_mark:</td>
<td><a href="https://develocity.apache.org/s/63plo64ycvihm" rel="nofollow"><img src="https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle" alt="Build Scan PUBLISHED" /></a></td>
</tr>
<tr>
<td>build-ubuntu-latest</td>
<td>clean install</td>
<td align='center'>3.9.8</td>
<td align='center'>:white_check_mark:</td>
<td><a href="https://develocity.apache.org/s/rkv7au2pzen2o" rel="nofollow"><img src="https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle" alt="Build Scan PUBLISHED" /></a></td>
</tr>
<tr>
<td>build-windows-latest</td>
<td>clean install</td>
<td align='center'>3.9.8</td>
<td align='center'>:white_check_mark:</td>
<td><a href="https://develocity.apache.org/s/jauf23npo3pae" rel="nofollow"><img src="https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle" alt="Build Scan PUBLISHED" /></a></td>
</tr>
</table>
###### Generated by gradle/develocity-actions
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "rschmitt (via GitHub)" <gi...@apache.org>.
rschmitt commented on code in PR #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675#discussion_r2104976807
##########
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 relieved to hear you say this
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz merged PR #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "rschmitt (via GitHub)" <gi...@apache.org>.
rschmitt commented on PR #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675#issuecomment-2892317246
@vy OK
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675#issuecomment-2892173764
Wouldn't it be better to
1. `ReadOnlyStringMapUtil` *internal* class such that
* It contains a static `equals(ReadOnlyStringMap,ReadOnlyStringMap)` method
* It contains a `hashCode(ReadOnlyStringMap)` method
2. Use `ReadOnlyStringMapUtil` to implement `equals` and `hashCode` in *all* `ReadOnlyStringMap` implementations
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StringMap: Generalize `equals`/`hashCode` across implementations [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #3675:
URL: https://github.com/apache/logging-log4j2/pull/3675#issuecomment-2900304151
@rschmitt, bump the `@Version` tag to `2.25.0` in `package-info.java` files located where you touched files. (Just answering your question, next week I will review your PR in detail.)
--
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-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org