Introduce fall-through handling of recursion in lazy values

Fixed EA-52272 - NA: LockBasedStorageManager$LockBasedLazyValue.recursionDetected
This commit is contained in:
Andrey Breslav
2013-12-20 17:40:37 +04:00
parent 44e055e698
commit ac191a7dbb
2 changed files with 87 additions and 12 deletions
@@ -384,6 +384,27 @@ public class StorageManagerTest extends TestCase {
assertEquals("second", c.rec.invoke());
}
public void testFallThrough() throws Exception {
final CounterImpl c = new CounterImpl();
class C {
NotNullLazyValue<Integer> rec = LockBasedStorageManager.NO_LOCKS.createLazyValue(new Function0<Integer>() {
@Override
public Integer invoke() {
c.inc();
if (c.getCount() < 2) {
return rec.invoke();
}
else {
return c.getCount();
}
}
});
}
assertEquals(2, new C().rec.invoke().intValue());
assertEquals(2, c.getCount());
}
// Utilities
private static <K, V> Function0<V> apply(final Function1<K, V> f, final K x) {