Apache Lucene open-source search software
LUCENE-6430: FilterPath needs hashCode/equals
Robert Muir5cbdc93244f0
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 81976261535..5b80b059028 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -94,8 +94,9 @@ Bug Fixes* LUCENE-6409: Fixed integer overflow in LongBitSet.ensureCapacity.(Luc Vanlerberghe via Adrien Grand)-* LUCENE-6424: Fix many bugs with mockfs filesystems in the test-framework:- always consistently wrap Path, fix buggy behavior for globs, etc.+* LUCENE-6424, LUCENE-6430: Fix many bugs with mockfs filesystems in the+ test-framework: always consistently wrap Path, fix buggy behavior for+ globs, implement equals/hashcode for filtered Paths, etc.(Ryan Ernst, Simon Willnauer, Robert Muir)* LUCENE-6426: Fix FieldType's copy constructor to also copy over the numericdiff --git a/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.java b/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.javaindex 65e78e3ca0f..04800015eb7 100644--- a/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.java+++ b/lucene/core/src/test/org/apache/lucene/mockfile/TestMockFilesystems.java@@ -341,4 +341,20 @@ public class TestMockFilesystems extends LuceneTestCase {assertEquals(1, count);}}++ public void testHashCodeEquals() throws IOException {+ Path dir = FilterPath.unwrap(createTempDir());+ FileSystem fs = new FilterFileSystemProvider("test://", dir.getFileSystem()).getFileSystem(URI.create("file:///"));+ Path wrapped = new FilterPath(dir, fs);++ Path f1 = wrapped.resolve("file1");+ Path f1Again = wrapped.resolve("file1");+ Path f2 = wrapped.resolve("file2");++ assertEquals(f1, f1);+ assertFalse(f1.equals(null));+ assertEquals(f1, f1Again);+ assertEquals(f1.hashCode(), f1Again.hashCode());+ assertFalse(f1.equals(f2));+ }}diff --git a/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterPath.java b/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterPath.javaindex f6d907afd3b..8b824095e4e 100644--- a/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterPath.java+++ b/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterPath.java@@ -234,6 +234,26 @@ public class FilterPath implements Path {return delegate.compareTo(toDelegate(other));}+ @Override+ public int hashCode() {+ return delegate.hashCode();+ }++ @Override+ public boolean equals(Object obj) {+ if (this == obj) return true;+ if (obj == null) return false;+ if (getClass() != obj.getClass()) return false;+ FilterPath other = (FilterPath) obj;+ if (delegate == null) {+ if (other.delegate != null) return false;+ } else if (!delegate.equals(other.delegate)) return false;+ if (fileSystem == null) {+ if (other.fileSystem != null) return false;+ } else if (!fileSystem.equals(other.fileSystem)) return false;+ return true;+ }+/*** Unwraps all {@code FilterPath}s, returning* the innermost {@code Path}.