You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2018/02/08 17:31:35 UTC
[2/4] lucene-solr:branch_7x: LUCENE-7966: Build Multi-Release JARs to
enable usage of optimized intrinsic methods from Java 9 for index bounds
checking and array comparison/mismatch
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/core/src/test/org/apache/lucene/util/TestFutureArrays.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestFutureArrays.java b/lucene/core/src/test/org/apache/lucene/util/TestFutureArrays.java
new file mode 100644
index 0000000..1c128ed
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/util/TestFutureArrays.java
@@ -0,0 +1,305 @@
+/*
+ * 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.lucene.util;
+
+import java.nio.charset.StandardCharsets;
+
+/** Test java 8-compatible implementations of {@code java.util.Arrays} methods */
+public class TestFutureArrays extends LuceneTestCase {
+
+ public void testByteMismatch() {
+ assertEquals(1, FutureArrays.mismatch(bytes("ab"), 0, 2, bytes("ac"), 0, 2));
+ assertEquals(0, FutureArrays.mismatch(bytes("ab"), 0, 2, bytes("b"), 0, 1));
+ assertEquals(-1, FutureArrays.mismatch(bytes("ab"), 0, 2, bytes("ab"), 0, 2));
+ assertEquals(1, FutureArrays.mismatch(bytes("ab"), 0, 2, bytes("a"), 0, 1));
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.mismatch(bytes("ab"), 2, 1, bytes("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.mismatch(bytes("ab"), 2, 1, bytes("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.mismatch(null, 0, 2, bytes("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.mismatch(bytes("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.mismatch(bytes("ab"), 0, 3, bytes("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.mismatch(bytes("ab"), 0, 2, bytes("a"), 0, 2);
+ });
+ }
+
+ public void testCharMismatch() {
+ assertEquals(1, FutureArrays.mismatch(chars("ab"), 0, 2, chars("ac"), 0, 2));
+ assertEquals(0, FutureArrays.mismatch(chars("ab"), 0, 2, chars("b"), 0, 1));
+ assertEquals(-1, FutureArrays.mismatch(chars("ab"), 0, 2, chars("ab"), 0, 2));
+ assertEquals(1, FutureArrays.mismatch(chars("ab"), 0, 2, chars("a"), 0, 1));
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.mismatch(chars("ab"), 2, 1, chars("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.mismatch(chars("ab"), 2, 1, chars("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.mismatch(null, 0, 2, chars("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.mismatch(chars("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.mismatch(chars("ab"), 0, 3, chars("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.mismatch(chars("ab"), 0, 2, chars("a"), 0, 2);
+ });
+ }
+
+ public void testByteCompareUnsigned() {
+ assertEquals(1, Integer.signum(FutureArrays.compareUnsigned(bytes("ab"), 0, 2, bytes("a"), 0, 1)));
+ assertEquals(1, Integer.signum(FutureArrays.compareUnsigned(bytes("ab"), 0, 2, bytes("aa"), 0, 2)));
+ assertEquals(0, Integer.signum(FutureArrays.compareUnsigned(bytes("ab"), 0, 2, bytes("ab"), 0, 2)));
+ assertEquals(-1, Integer.signum(FutureArrays.compareUnsigned(bytes("a"), 0, 1, bytes("ab"), 0, 2)));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compareUnsigned(bytes("ab"), 2, 1, bytes("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compareUnsigned(bytes("ab"), 2, 1, bytes("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compareUnsigned(null, 0, 2, bytes("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compareUnsigned(bytes("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compareUnsigned(bytes("ab"), 0, 3, bytes("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compareUnsigned(bytes("ab"), 0, 2, bytes("a"), 0, 2);
+ });
+ }
+
+ public void testCharCompare() {
+ assertEquals(1, Integer.signum(FutureArrays.compare(chars("ab"), 0, 2, chars("a"), 0, 1)));
+ assertEquals(1, Integer.signum(FutureArrays.compare(chars("ab"), 0, 2, chars("aa"), 0, 2)));
+ assertEquals(0, Integer.signum(FutureArrays.compare(chars("ab"), 0, 2, chars("ab"), 0, 2)));
+ assertEquals(-1, Integer.signum(FutureArrays.compare(chars("a"), 0, 1, chars("ab"), 0, 2)));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compare(chars("ab"), 2, 1, chars("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compare(chars("ab"), 2, 1, chars("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compare(null, 0, 2, chars("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compare(chars("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compare(chars("ab"), 0, 3, chars("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compare(chars("ab"), 0, 2, chars("a"), 0, 2);
+ });
+ }
+
+ public void testIntCompare() {
+ assertEquals(1, Integer.signum(FutureArrays.compare(ints("ab"), 0, 2, ints("a"), 0, 1)));
+ assertEquals(1, Integer.signum(FutureArrays.compare(ints("ab"), 0, 2, ints("aa"), 0, 2)));
+ assertEquals(0, Integer.signum(FutureArrays.compare(ints("ab"), 0, 2, ints("ab"), 0, 2)));
+ assertEquals(-1, Integer.signum(FutureArrays.compare(ints("a"), 0, 1, ints("ab"), 0, 2)));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compare(ints("ab"), 2, 1, ints("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compare(ints("ab"), 2, 1, ints("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compare(null, 0, 2, ints("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compare(ints("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compare(ints("ab"), 0, 3, ints("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compare(ints("ab"), 0, 2, ints("a"), 0, 2);
+ });
+ }
+
+ public void testLongCompare() {
+ assertEquals(1, Integer.signum(FutureArrays.compare(longs("ab"), 0, 2, longs("a"), 0, 1)));
+ assertEquals(1, Integer.signum(FutureArrays.compare(longs("ab"), 0, 2, longs("aa"), 0, 2)));
+ assertEquals(0, Integer.signum(FutureArrays.compare(longs("ab"), 0, 2, longs("ab"), 0, 2)));
+ assertEquals(-1, Integer.signum(FutureArrays.compare(longs("a"), 0, 1, longs("ab"), 0, 2)));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compare(longs("ab"), 2, 1, longs("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.compare(longs("ab"), 2, 1, longs("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compare(null, 0, 2, longs("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.compare(longs("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compare(longs("ab"), 0, 3, longs("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.compare(longs("ab"), 0, 2, longs("a"), 0, 2);
+ });
+ }
+
+ public void testByteEquals() {
+ assertFalse(FutureArrays.equals(bytes("ab"), 0, 2, bytes("a"), 0, 1));
+ assertFalse(FutureArrays.equals(bytes("ab"), 0, 2, bytes("aa"), 0, 2));
+ assertTrue(FutureArrays.equals(bytes("ab"), 0, 2, bytes("ab"), 0, 2));
+ assertFalse(FutureArrays.equals(bytes("a"), 0, 1, bytes("ab"), 0, 2));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(bytes("ab"), 2, 1, bytes("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(bytes("ab"), 2, 1, bytes("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(null, 0, 2, bytes("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(bytes("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(bytes("ab"), 0, 3, bytes("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(bytes("ab"), 0, 2, bytes("a"), 0, 2);
+ });
+ }
+
+ public void testCharEquals() {
+ assertFalse(FutureArrays.equals(chars("ab"), 0, 2, chars("a"), 0, 1));
+ assertFalse(FutureArrays.equals(chars("ab"), 0, 2, chars("aa"), 0, 2));
+ assertTrue(FutureArrays.equals(chars("ab"), 0, 2, chars("ab"), 0, 2));
+ assertFalse(FutureArrays.equals(chars("a"), 0, 1, chars("ab"), 0, 2));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(chars("ab"), 2, 1, chars("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(chars("ab"), 2, 1, chars("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(null, 0, 2, chars("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(chars("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(chars("ab"), 0, 3, chars("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(chars("ab"), 0, 2, chars("a"), 0, 2);
+ });
+ }
+
+ public void testIntEquals() {
+ assertFalse(FutureArrays.equals(ints("ab"), 0, 2, ints("a"), 0, 1));
+ assertFalse(FutureArrays.equals(ints("ab"), 0, 2, ints("aa"), 0, 2));
+ assertTrue(FutureArrays.equals(ints("ab"), 0, 2, ints("ab"), 0, 2));
+ assertFalse(FutureArrays.equals(ints("a"), 0, 1, ints("ab"), 0, 2));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(ints("ab"), 2, 1, ints("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(ints("ab"), 2, 1, ints("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(null, 0, 2, ints("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(ints("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(ints("ab"), 0, 3, ints("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(ints("ab"), 0, 2, ints("a"), 0, 2);
+ });
+ }
+
+ public void testLongEquals() {
+ assertFalse(FutureArrays.equals(longs("ab"), 0, 2, longs("a"), 0, 1));
+ assertFalse(FutureArrays.equals(longs("ab"), 0, 2, longs("aa"), 0, 2));
+ assertTrue(FutureArrays.equals(longs("ab"), 0, 2, longs("ab"), 0, 2));
+ assertFalse(FutureArrays.equals(longs("a"), 0, 1, longs("ab"), 0, 2));
+
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(longs("ab"), 2, 1, longs("a"), 0, 1);
+ });
+ expectThrows(IllegalArgumentException.class, () -> {
+ FutureArrays.equals(longs("ab"), 2, 1, longs("a"), 1, 0);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(null, 0, 2, longs("a"), 0, 1);
+ });
+ expectThrows(NullPointerException.class, () -> {
+ FutureArrays.equals(longs("ab"), 0, 2, null, 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(longs("ab"), 0, 3, longs("a"), 0, 1);
+ });
+ expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureArrays.equals(longs("ab"), 0, 2, longs("a"), 0, 2);
+ });
+ }
+
+ private byte[] bytes(String s) {
+ return s.getBytes(StandardCharsets.UTF_8);
+ }
+
+ private char[] chars(String s) {
+ return s.toCharArray();
+ }
+
+ private int[] ints(String s) {
+ int ints[] = new int[s.length()];
+ for (int i = 0; i < s.length(); i++) {
+ ints[i] = s.charAt(i);
+ }
+ return ints;
+ }
+
+ private long[] longs(String s) {
+ long longs[] = new long[s.length()];
+ for (int i = 0; i < s.length(); i++) {
+ longs[i] = s.charAt(i);
+ }
+ return longs;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/core/src/test/org/apache/lucene/util/TestFutureObjects.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestFutureObjects.java b/lucene/core/src/test/org/apache/lucene/util/TestFutureObjects.java
new file mode 100644
index 0000000..ed1ad36
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/util/TestFutureObjects.java
@@ -0,0 +1,102 @@
+/*
+ * 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.lucene.util;
+
+/** Test java 8-compatible implementations of {@code java.util.Objects} methods */
+public class TestFutureObjects extends LuceneTestCase {
+
+ public void testCheckIndex() {
+ assertEquals(0, FutureObjects.checkIndex(0, 1));
+ assertEquals(1, FutureObjects.checkIndex(1, 2));
+
+ Exception e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkIndex(-1, 0);
+ });
+ assertEquals("Index -1 out-of-bounds for length 0", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkIndex(0, 0);
+ });
+ assertEquals("Index 0 out-of-bounds for length 0", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkIndex(1, 0);
+ });
+ assertEquals("Index 1 out-of-bounds for length 0", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkIndex(0, -1);
+ });
+ assertEquals("Index 0 out-of-bounds for length -1", e.getMessage());
+ }
+
+ public void testCheckFromToIndex() {
+ assertEquals(0, FutureObjects.checkFromToIndex(0, 0, 0));
+ assertEquals(1, FutureObjects.checkFromToIndex(1, 2, 2));
+
+ Exception e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromToIndex(-1, 0, 0);
+ });
+ assertEquals("Range [-1, 0) out-of-bounds for length 0", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromToIndex(1, 0, 2);
+ });
+ assertEquals("Range [1, 0) out-of-bounds for length 2", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromToIndex(1, 3, 2);
+ });
+ assertEquals("Range [1, 3) out-of-bounds for length 2", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromToIndex(0, 0, -1);
+ });
+ assertEquals("Range [0, 0) out-of-bounds for length -1", e.getMessage());
+ }
+
+ public void testCheckFromIndexSize() {
+ assertEquals(0, FutureObjects.checkFromIndexSize(0, 0, 0));
+ assertEquals(1, FutureObjects.checkFromIndexSize(1, 2, 3));
+
+ Exception e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromIndexSize(-1, 0, 1);
+ });
+ assertEquals("Range [-1, -1 + 0) out-of-bounds for length 1", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromIndexSize(0, -1, 1);
+ });
+ assertEquals("Range [0, 0 + -1) out-of-bounds for length 1", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromIndexSize(0, 2, 1);
+ });
+ assertEquals("Range [0, 0 + 2) out-of-bounds for length 1", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromIndexSize(1, Integer.MAX_VALUE, Integer.MAX_VALUE);
+ });
+ assertEquals("Range [1, 1 + 2147483647) out-of-bounds for length 2147483647", e.getMessage());
+
+ e = expectThrows(IndexOutOfBoundsException.class, () -> {
+ FutureObjects.checkFromIndexSize(0, 0, -1);
+ });
+ assertEquals("Range [0, 0 + 0) out-of-bounds for length -1", e.getMessage());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java b/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
index 58c3030..97e1c2e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestStringHelper.java
@@ -23,6 +23,15 @@ public class TestStringHelper extends LuceneTestCase {
BytesRef left = new BytesRef("foobar");
BytesRef right = new BytesRef("foozo");
assertEquals(3, StringHelper.bytesDifference(left, right));
+ assertEquals(2, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("for")));
+ assertEquals(2, StringHelper.bytesDifference(new BytesRef("foo1234"), new BytesRef("for1234")));
+ assertEquals(1, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("fz")));
+ assertEquals(0, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("g")));
+ assertEquals(3, StringHelper.bytesDifference(new BytesRef("foo"), new BytesRef("food")));
+ // we can detect terms are out of order if we see a duplicate
+ expectThrows(IllegalArgumentException.class, () -> {
+ StringHelper.bytesDifference(new BytesRef("ab"), new BytesRef("ab"));
+ });
}
public void testStartsWith() {
@@ -63,5 +72,9 @@ public class TestStringHelper extends LuceneTestCase {
assertEquals(2, StringHelper.sortKeyLength(new BytesRef("foo"), new BytesRef("fz")));
assertEquals(1, StringHelper.sortKeyLength(new BytesRef("foo"), new BytesRef("g")));
assertEquals(4, StringHelper.sortKeyLength(new BytesRef("foo"), new BytesRef("food")));
+ // we can detect terms are out of order if we see a duplicate
+ expectThrows(IllegalArgumentException.class, () -> {
+ StringHelper.sortKeyLength(new BytesRef("ab"), new BytesRef("ab"));
+ });
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
index 15251ad..9e20cb5 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestUnicodeUtil.java
@@ -16,7 +16,6 @@
*/
package org.apache.lucene.util;
-
/*
* Some of this code came from the excellent Unicode
* conversion examples from:
@@ -143,7 +142,7 @@ public class TestUnicodeUtil extends LuceneTestCase {
final int utf32Len = UnicodeUtil.UTF8toUTF32(new BytesRef(utf8, 0, utf8Len), utf32);
int[] codePoints = s.codePoints().toArray();
- if (!ArrayUtil.equals(codePoints, 0, utf32, 0, codePoints.length)) {
+ if (!FutureArrays.equals(codePoints, 0, codePoints.length, utf32, 0, codePoints.length)) {
System.out.println("FAILED");
for(int j=0;j<s.length();j++) {
System.out.println(" char[" + j + "]=" + Integer.toHexString(s.charAt(j)));
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyWriter.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyWriter.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyWriter.java
index 1561e2a..6061754 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyWriter.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyWriter.java
@@ -79,7 +79,7 @@ public interface TaxonomyWriter extends Closeable, TwoPhaseCommit {
* If the given ordinal is the ROOT_ORDINAL, an INVALID_ORDINAL is returned.
* If the given ordinal is a top-level category, the ROOT_ORDINAL is returned.
* If an invalid ordinal is given (negative or beyond the last available
- * ordinal), an ArrayIndexOutOfBoundsException is thrown. However, it is
+ * ordinal), an IndexOutOfBoundsException is thrown. However, it is
* expected that getParent will only be called for ordinals which are
* already known to be in the taxonomy.
* TODO (Facet): instead of a getParent(ordinal) method, consider having a
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
index 00f9b72..0ed7fc6 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
@@ -61,6 +61,7 @@ import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FutureObjects;
/**
* {@link TaxonomyWriter} which uses a {@link Directory} to store the taxonomy
@@ -763,9 +764,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
// Note: the following if() just enforces that a user can never ask
// for the parent of a nonexistant category - even if the parent array
// was allocated bigger than it really needs to be.
- if (ordinal >= nextID) {
- throw new ArrayIndexOutOfBoundsException("requested ordinal is bigger than the largest ordinal in the taxonomy");
- }
+ FutureObjects.checkIndex(ordinal, nextID);
int[] parents = getTaxoArrays().parents();
assert ordinal < parents.length : "requested ordinal (" + ordinal + "); parents.length (" + parents.length + ") !";
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
index ecf1401..b2f33b2 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
@@ -490,13 +490,13 @@ public class TestTaxonomyCombined extends FacetTestCase {
}
// check parent of of invalid ordinals:
- expectThrows(ArrayIndexOutOfBoundsException.class, () -> {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
tw.getParent(-1);
});
- expectThrows(ArrayIndexOutOfBoundsException.class, () -> {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
tw.getParent(TaxonomyReader.INVALID_ORDINAL);
});
- expectThrows(ArrayIndexOutOfBoundsException.class, () -> {
+ expectThrows(IndexOutOfBoundsException.class, () -> {
tw.getParent(tr.getSize());
});
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/module-build.xml
----------------------------------------------------------------------
diff --git a/lucene/module-build.xml b/lucene/module-build.xml
index c2159b6..92ca60e 100644
--- a/lucene/module-build.xml
+++ b/lucene/module-build.xml
@@ -34,11 +34,20 @@
<!-- default classpath refid, can be overridden by contrib's build.xml (use the above base.classpath as basis): -->
<path id="classpath" refid="base.classpath"/>
+ <!-- if we run with Java 9+, we refer to the java9 classes directory and insert this before the main classpath (to "emulate" a MR-JAR): -->
+ <condition property="-test.classpath.java9.addon" value="${build.dir}/classes/java9" else="${build.dir}/classes/java">
+ <and>
+ <not><equals arg1="${build.java.runtime}" arg2="1.8"/></not>
+ <istrue value="${tests.withJava9Patches}"/>
+ </and>
+ </condition>
+
<path id="test.base.classpath">
<pathelement location="${common.dir}/build/test-framework/classes/java"/>
<pathelement location="${common.dir}/build/codecs/classes/java"/>
<path refid="classpath"/>
<path refid="junit-path"/>
+ <pathelement location="${-test.classpath.java9.addon}"/><!-- if it's a duplicate it gets removed by Ant! -->
<pathelement location="${build.dir}/classes/java"/>
</path>
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/lucene/tools/src/groovy/patch-mrjar-classes.groovy
----------------------------------------------------------------------
diff --git a/lucene/tools/src/groovy/patch-mrjar-classes.groovy b/lucene/tools/src/groovy/patch-mrjar-classes.groovy
new file mode 100644
index 0000000..d169997
--- /dev/null
+++ b/lucene/tools/src/groovy/patch-mrjar-classes.groovy
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+import org.apache.tools.ant.Project;
+
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.commons.ClassRemapper;
+import org.objectweb.asm.commons.Remapper;
+
+def mappings = [
+ 'org/apache/lucene/util/FutureObjects': 'java/util/Objects',
+ 'org/apache/lucene/util/FutureArrays': 'java/util/Arrays',
+];
+
+File inputDir = new File(properties['build.dir'], 'classes/java');
+File outputDir = new File(properties['build.dir'], 'classes/java9');
+
+outputDir.mkdirs();
+
+def scanner = ant.fileScanner {
+ fileset(dir:inputDir) {
+ include(name:"**/*.class")
+ }
+}
+
+int count = 0;
+for (f in scanner) {
+ ClassReader reader = new ClassReader(f.getBytes());
+ if (mappings.containsKey(reader.className)) {
+ // we do not remap our replacements! :-)
+ continue;
+ }
+
+ ClassWriter writer = new ClassWriter(0 /* no recalculations needed */);
+ boolean remapped = false;
+ ClassRemapper remapper = new ClassRemapper(writer, new Remapper() {
+ @Override
+ public String map(String typeName) {
+ if (mappings.containsKey(typeName)) {
+ remapped = true;
+ return mappings.get(typeName);
+ }
+ return typeName;
+ }
+ });
+
+ reader.accept(remapper, 0 /* keep everything as-is*/);
+
+ if (remapped) {
+ task.log("Remapped: "+reader.className, Project.MSG_INFO);
+ File output = new File(outputDir, reader.className + '.class');
+ output.parentFile.mkdirs();
+ output.setBytes(writer.toByteArray());
+ count++;
+ }
+}
+
+task.log("Remapped $count class files for Java 9 to: $outputDir", Project.MSG_INFO);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/621f5ece/solr/common-build.xml
----------------------------------------------------------------------
diff --git a/solr/common-build.xml b/solr/common-build.xml
index ec37848..9975a73 100644
--- a/solr/common-build.xml
+++ b/solr/common-build.xml
@@ -555,4 +555,7 @@
<target name="test" unless="tests.disable-solr">
<antcall target="common.test" inheritrefs="true" inheritall="true"/>
</target>
+
+ <!-- In Solr we do not generate MR-JARs yet; disable completely so we do not accidentally patch -->
+ <target name="patch-mrjar-classes"/>
</project>