From 9771bdb9a2f2f5800ab134a53eb7b0722347dc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Fri, 3 Jul 2026 13:18:45 +0200 Subject: [PATCH 1/2] Fix reference-equality comparisons flagged by Error Prone 2.50.0 - ZkMaintenanceUtils: compared Path objects with == in the single-file upload case, so uploading a single file could take the wrong branch - HttpShardHandler: compared a request-context Boolean with ==; now Boolean.TRUE.equals(...) so any true value enables onlyNrt - ZkShardTermsTest.waitFor: compared boxed values by reference, always burning the 10s timeout for values outside the Integer cache - Utils: document that the ClassLoader cache guard intentionally uses identity, and suppress the future ReferenceEquality finding --- .../org/apache/solr/handler/component/HttpShardHandler.java | 2 +- solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java | 2 +- .../java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java | 2 +- solr/solrj/src/java/org/apache/solr/common/util/Utils.java | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java index 34f9a022d70d..da2847210809 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java @@ -496,7 +496,7 @@ public void prepDistributed(ResponseBuilder rb) { ReplicaSource replicaSource; if (zkController != null) { - boolean onlyNrt = Boolean.TRUE == req.getContext().get(ONLY_NRT_REPLICAS); + boolean onlyNrt = Boolean.TRUE.equals(req.getContext().get(ONLY_NRT_REPLICAS)); replicaSource = new CloudReplicaSource.Builder() diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java index 7aed2e27d3d4..883af88f3142 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java @@ -380,7 +380,7 @@ public void testSetHighestTerms() throws Exception { private void waitFor(T expected, Supplier supplier) throws InterruptedException { TimeOut timeOut = new TimeOut(10, TimeUnit.SECONDS, new TimeSource.CurrentTimeSource()); while (!timeOut.hasTimedOut()) { - if (expected == supplier.get()) return; + if (Objects.equals(expected, supplier.get())) return; Thread.sleep(100); } assertEquals(expected, supplier.get()); diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java index 6438e84bbfce..4efb08274130 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java @@ -349,7 +349,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) if (file.getFileName().toString().equals(ZKNODE_DATA_FILE) && zkClient.exists(zkNode)) { zkClient.setData(zkNode, file); - } else if (file == rootPath) { + } else if (file.equals(rootPath)) { // We are only uploading a single file, preVisitDirectory was never called if (zkClient.exists(zkPath)) { zkClient.setData(zkPath, file); diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java index 982d706590db..acbbdac41d72 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java @@ -905,6 +905,8 @@ private static List getReflectData( Class catchAllAnnotation, Function fieldNamer) throws IllegalAccessException { + // ClassLoader identity (not equals) determines whether it is safe to cache reflective metadata. + @SuppressWarnings("ReferenceEquality") boolean sameClassLoader = c.getClassLoader() == Utils.class.getClassLoader(); // we should not cache the class references of objects loaded from packages because they will // not get garbage collected From aab50fe396f5c5e98d420ac17e16d8e1ae8f870a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Fri, 3 Jul 2026 13:19:14 +0200 Subject: [PATCH 2/2] Add changelog entry --- changelog/unreleased/PR#4605-reference-equality-fixes.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/PR#4605-reference-equality-fixes.yml diff --git a/changelog/unreleased/PR#4605-reference-equality-fixes.yml b/changelog/unreleased/PR#4605-reference-equality-fixes.yml new file mode 100644 index 000000000000..6b8aa46a556f --- /dev/null +++ b/changelog/unreleased/PR#4605-reference-equality-fixes.yml @@ -0,0 +1,8 @@ +# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc +title: Fix reference-equality comparison bugs in ZkMaintenanceUtils single-file upload and HttpShardHandler onlyNrt detection +type: fixed +authors: + - name: Jan Høydahl +links: +- name: PR#4605 + url: https://github.com/apache/solr/pull/4605