laurentgo commented on a change in pull request #11063:
URL: https://github.com/apache/arrow/pull/11063#discussion_r701339753



##########
File path: 
java/memory/memory-core/src/main/java/org/apache/arrow/util/AutoCloseables.java
##########
@@ -113,9 +114,23 @@ public static void close(Iterable<? extends AutoCloseable> 
ac) throws Exception
    */
   @SafeVarargs
   public static void close(Iterable<? extends AutoCloseable>...closeables) 
throws Exception {
-    close(Arrays.asList(closeables).stream()
-        .flatMap((Iterable<? extends AutoCloseable> t) -> 
Collections2.toList(t).stream())
-        .collect(Collectors.toList()));
+    close(flatten(closeables));
+  }
+
+  @SafeVarargs
+  private static Iterable<AutoCloseable> flatten(Iterable<? extends 
AutoCloseable>... closeables) {
+    return new Iterable<AutoCloseable>() {
+      // Cast from Iterable<? extends AutoCloseable> to 
Iterable<AutoCloseable> is safe in this context
+      // since there's no modification of the original collection
+      @SuppressWarnings("unchecked")
+      @Override
+      public Iterator<AutoCloseable> iterator() {
+        return Arrays.stream(closeables)
+            .flatMap((Iterable<? extends AutoCloseable> i)
+                -> StreamSupport.stream(((Iterable<AutoCloseable>) 
i).spliterator(), false))

Review comment:
       Hopefully addressed by latest commit




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to