This is an automated email from the ASF dual-hosted git repository.
daim pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 88c8a2cc12 OAK-11557 : removed usage of Guava's
Iterables.getOnlyElements with S… (#2147)
88c8a2cc12 is described below
commit 88c8a2cc12de11b59c1d46ff60674742fd7208d5
Author: Rishabh Kumar <[email protected]>
AuthorDate: Fri Mar 7 18:24:12 2025 +0530
OAK-11557 : removed usage of Guava's Iterables.getOnlyElements with S…
(#2147)
* OAK-11556 : removed usage of Guava's Iterables.getOnlyElements with
Streams
* OAK-11557 : fixed unit cases, happened due to consumption of Iterable
twice
* OAK-11557 : removed un-used imports
---------
Co-authored-by: Rishabh Kumar <[email protected]>
---
.../main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java | 4 +++-
.../jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java | 3 ++-
.../oak/plugins/index/search/spi/query/FulltextIndexPlanner.java | 2 +-
.../org/apache/jackrabbit/oak/plugins/index/OrderByCommonTest.java | 3 ++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
index 70f4ca8631..6277a25641 100644
---
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
+++
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
@@ -250,7 +250,9 @@ public final class IndexUtils {
asyncNames.remove(IndexConstants.INDEXING_MODE_SYNC);
checkArgument(!asyncNames.isEmpty(), "No valid async name found
for " +
"index [%s], definition %s", indexPath, idxState);
- return Iterables.getOnlyElement(asyncNames);
+ checkArgument(asyncNames.size() == 1, "Multiple async names found
for " +
+ "index [%s], definition %s", indexPath, idxState);
+ return asyncNames.stream().findAny().orElseThrow();
}
return null;
}
diff --git
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
index dd022011f7..f0f926514a 100644
---
a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
+++
b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
@@ -60,6 +60,7 @@ import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
+import org.apache.jackrabbit.oak.commons.collections.StreamUtils;
import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService;
import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl;
@@ -3123,7 +3124,7 @@ public class LucenePropertyIndexTest extends
AbstractQueryTest {
private String explainXpath(String query) throws ParseException {
String explain = "explain " + query;
Result result = executeQuery(explain, "xpath", NO_BINDINGS);
- ResultRow row = Iterables.getOnlyElement(result.getRows());
+ ResultRow row =
StreamUtils.toStream(result.getRows()).findAny().orElseThrow();
return row.getValue("plan").getValue(Type.STRING);
}
diff --git
a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
index 65e62e7e93..173127a6ee 100644
---
a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
+++
b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
@@ -591,7 +591,7 @@ public class FulltextIndexPlanner {
log.debug("Following relative property paths are not index:
{}", relPaths);
return false;
}
- result.setParentPath(Iterables.getOnlyElement(relPaths, ""));
+ result.setParentPath(relPaths.stream().findAny().orElse(""));
//Such non indexed path can possibly be evaluated via any rule on
nt:base
//which can possibly index everything
diff --git
a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/OrderByCommonTest.java
b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/OrderByCommonTest.java
index 4322ca998c..62c9757e8f 100644
---
a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/OrderByCommonTest.java
+++
b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/OrderByCommonTest.java
@@ -23,6 +23,7 @@ import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
+import org.apache.jackrabbit.oak.commons.collections.StreamUtils;
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import
org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder;
import org.apache.jackrabbit.oak.query.AbstractQueryTest;
@@ -512,7 +513,7 @@ public abstract class OrderByCommonTest extends
AbstractQueryTest {
} catch (ParseException e) {
throw new RuntimeException(e);
}
- ResultRow row = Iterables.getOnlyElement(result.getRows());
+ ResultRow row =
StreamUtils.toStream(result.getRows()).findAny().orElseThrow();
return row.getValue("plan").getValue(Type.STRING);
}