From cd426ef0b2ff22773e02a3d5c0e879e2b989fe1b Mon Sep 17 00:00:00 2001 From: John McClean Date: Wed, 12 Apr 2017 14:56:50 +0100 Subject: [PATCH] 7.2.4-fix --- .../java/com/aol/cyclops/trycatch/Try.java | 31 ++++++++++--------- .../com/aol/cyclops/trycatch/TryTest.java | 12 ++++++- gradle.properties | 2 +- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/cyclops-try/src/main/java/com/aol/cyclops/trycatch/Try.java b/cyclops-try/src/main/java/com/aol/cyclops/trycatch/Try.java index ae41fb3d..f2f2dd2d 100644 --- a/cyclops-try/src/main/java/com/aol/cyclops/trycatch/Try.java +++ b/cyclops-try/src/main/java/com/aol/cyclops/trycatch/Try.java @@ -144,7 +144,7 @@ public interface Try extends Supplier, ValueObject, To * Flatten a nested Try Structure * @return Lowest nested Try */ - public Try flatten(); + public Try flatten(); /** * @return Optional present if Success, Optional empty if failure @@ -319,24 +319,25 @@ public static class MyFinallyBlock implements AndFinall private final Class[] classes; private final CheckedSupplier inputSupplier; private final CheckedFunction catchBlock; - + private void invokeClose(Object in) { - if(in instanceof Iterable) + if(in instanceof Closeable || in instanceof AutoCloseable) + _invokeClose(in); + else if(in instanceof Iterable) invokeClose((Iterable)in); - invokeClose((Closeable)in); } - private void invokeClose(Iterable in){ - for(Closeable next : in) + private void invokeClose(Iterable in){ + for(Object next : in) invokeClose(next); - - - } - private void invokeClose(Closeable in){ - - Try.withCatch(()->in.getClass().getMethod("close")).filter(m->m!=null) - .flatMap(m->Try.withCatch(()->m.invoke(in)) - .filter(o->o!=null)); - + + + } + private void _invokeClose(Object in){ + + Try.withCatch(()->in.getClass().getMethod("close")).filter(m->m!=null) + .flatMap(m->Try.withCatch(()->m.invoke(in)) + .filter(o->o!=null)); + } public Try close(){ diff --git a/cyclops-try/src/test/java/com/aol/cyclops/trycatch/TryTest.java b/cyclops-try/src/test/java/com/aol/cyclops/trycatch/TryTest.java index 3008c3f9..6dc0d92e 100644 --- a/cyclops-try/src/test/java/com/aol/cyclops/trycatch/TryTest.java +++ b/cyclops-try/src/test/java/com/aol/cyclops/trycatch/TryTest.java @@ -15,7 +15,17 @@ import com.aol.cyclops.lambda.tuple.PTuple2; import com.aol.cyclops.lambda.tuple.PowerTuples; public class TryTest { - + + + @Test + public void compileError(){ + Try r = Try.of(Try.of("r")) + .flatten(); + + + + + } @Test(expected=IOException.class) public void test(){ Try.runWithCatch(this::exceptional,IOException.class) diff --git a/gradle.properties b/gradle.properties index 4c1399fe..5740e602 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=7.2.0 +version=7.2.4 lombokVersion=1.16.2 joolVersion=0.9.7 pcollectionsVersion=2.1.2