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