This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b75877f5 CPD: Re-implement deprecated code to use new code
8b75877f5 is described below

commit 8b75877f5968311def4f46cfb601ce0defe1b4ae
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Aug 26 16:29:57 2022 -0400

    CPD: Re-implement deprecated code to use new code
---
 .../java/org/apache/commons/lang3/Functions.java   | 40 ++++------------------
 1 file changed, 6 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/Functions.java 
b/src/main/java/org/apache/commons/lang3/Functions.java
index 4d3c471d1..69dce38dc 100644
--- a/src/main/java/org/apache/commons/lang3/Functions.java
+++ b/src/main/java/org/apache/commons/lang3/Functions.java
@@ -32,6 +32,7 @@ import java.util.function.Supplier;
 import java.util.stream.Stream;
 
 import org.apache.commons.lang3.Streams.FailableStream;
+import org.apache.commons.lang3.function.Failable;
 import org.apache.commons.lang3.function.FailableBooleanSupplier;
 
 /**
@@ -629,41 +630,12 @@ public class Functions {
     public static void tryWithResources(final FailableRunnable<? extends 
Throwable> action,
         final FailableConsumer<Throwable, ? extends Throwable> errorHandler,
         final FailableRunnable<? extends Throwable>... resources) {
-        final FailableConsumer<Throwable, ? extends Throwable> 
actualErrorHandler;
-        if (errorHandler == null) {
-            actualErrorHandler = Functions::rethrow;
-        } else {
-            actualErrorHandler = errorHandler;
-        }
-        if (resources != null) {
-            for (final FailableRunnable<? extends Throwable> failableRunnable 
: resources) {
-                Objects.requireNonNull(failableRunnable, "runnable");
-            }
-        }
-        Throwable th = null;
-        try {
-            action.run();
-        } catch (final Throwable t) {
-            th = t;
-        }
-        if (resources != null) {
-            for (final FailableRunnable<?> runnable : resources) {
-                try {
-                    runnable.run();
-                } catch (final Throwable t) {
-                    if (th == null) {
-                        th = t;
-                    }
-                }
-            }
-        }
-        if (th != null) {
-            try {
-                actualErrorHandler.accept(th);
-            } catch (final Throwable t) {
-                throw rethrow(t);
-            }
+        org.apache.commons.lang3.function.FailableRunnable<?>[] fr = new 
org.apache.commons.lang3.function.FailableRunnable[resources.length];
+        for (int i = 0; i < resources.length; i++) {
+            final int fi = i;
+            fr[i] = () -> resources[fi].run();
         }
+        Failable.tryWithResources(action::run, errorHandler != null ? 
errorHandler::accept : null, fr);
     }
 
     /**

Reply via email to