aol / cyclops

An advanced, but easy to use, platform for writing functional applications in Java 8.

Home Page:http://cyclops-react.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infinite loop with recoverFlatMap

ayush-finix opened this issue · comments

Describe the bug
There's an infinite loop when using recoverFlatMap on lazyeithers. I found this when trying to reduce a nonempty list with a function chain.

I think the functions underneath are slightly easier to debug and capture the issue better.

To Reproduce
Steps to reproduce the behavior:

void infinite() {
    Try<String, Exception> result = Option.<String>none().toTry(new Exception("asdf"));
    for (int i = 0; i < 10; i++) {
      result = result.recoverFlatMap(e -> Option.<String>none().toTry(new Exception("asdf")));
    }
    System.out.println(result.toString());
  }

Compare to this (which returns correctly)

void terminates() {
    Try<String, Exception> result = Try.failure(new Exception("asdf"));
    for (int i = 0; i < 10; i++) {
      result = result.recoverFlatMap(e -> Try.failure(new Exception("asdf")));
    }
    System.out.println(result.toString());
  }

Expected behavior
Return the correct value (ex. what terminates() does)

Additional context
Tested on version 10.3.0 and 10.3.3, on jdk 8.

Fix merged.