Skip to content

Commit cd426ef

Browse files
committed
7.2.4-fix
1 parent 8d21cac commit cd426ef

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

cyclops-try/src/main/java/com/aol/cyclops/trycatch/Try.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public interface Try<T,X extends Throwable> extends Supplier<T>, ValueObject, To
144144
* Flatten a nested Try Structure
145145
* @return Lowest nested Try
146146
*/
147-
public Try<T,X> flatten();
147+
public <T> Try<T,X> flatten();
148148

149149
/**
150150
* @return Optional present if Success, Optional empty if failure
@@ -319,24 +319,25 @@ public static class MyFinallyBlock<T,V,X extends Throwable> implements AndFinall
319319
private final Class<X>[] classes;
320320
private final CheckedSupplier<V,X> inputSupplier;
321321
private final CheckedFunction<V, T, X> catchBlock;
322-
322+
323323
private void invokeClose(Object in) {
324-
if(in instanceof Iterable)
324+
if(in instanceof Closeable || in instanceof AutoCloseable)
325+
_invokeClose(in);
326+
else if(in instanceof Iterable)
325327
invokeClose((Iterable)in);
326-
invokeClose((Closeable)in);
327328
}
328-
private void invokeClose(Iterable<Closeable> in){
329-
for(Closeable next : in)
329+
private void invokeClose(Iterable in){
330+
for(Object next : in)
330331
invokeClose(next);
331-
332-
333-
}
334-
private void invokeClose(Closeable in){
335-
336-
Try.withCatch(()->in.getClass().getMethod("close")).filter(m->m!=null)
337-
.flatMap(m->Try.withCatch(()->m.invoke(in))
338-
.filter(o->o!=null));
339-
332+
333+
334+
}
335+
private void _invokeClose(Object in){
336+
337+
Try.withCatch(()->in.getClass().getMethod("close")).filter(m->m!=null)
338+
.flatMap(m->Try.withCatch(()->m.invoke(in))
339+
.filter(o->o!=null));
340+
340341
}
341342
public Try<T,X> close(){
342343

cyclops-try/src/test/java/com/aol/cyclops/trycatch/TryTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
1515
import com.aol.cyclops.lambda.tuple.PTuple2;
1616
import com.aol.cyclops.lambda.tuple.PowerTuples;
1717
public class TryTest {
18-
18+
19+
20+
@Test
21+
public void compileError(){
22+
Try<String, Throwable> r = Try.of(Try.of("r"))
23+
.flatten();
24+
25+
26+
27+
28+
}
1929
@Test(expected=IOException.class)
2030
public void test(){
2131
Try.runWithCatch(this::exceptional,IOException.class)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=7.2.0
1+
version=7.2.4
22
lombokVersion=1.16.2
33
joolVersion=0.9.7
44
pcollectionsVersion=2.1.2

0 commit comments

Comments
 (0)