Bug in b88: Stack Overflow when changing a Supplier to a lambda using LazySeq
Samir Talwar
samir at noodlesandwich.com
Sun May 26 10:29:03 PDT 2013
I wrote some code using the LazySeq library (
https://github.com/nurkiewicz/LazySeq ) which implements merge sort
given two already-sorted lists. It crashes with a stack overflow.
That works well. If I try and use lambdas, javac crashes with a stack overflow.
Lambdas code (MergeSortCrashing.java):
public static <T extends Comparable<T>> LazySeq<T>
mergeSorted(LazySeq<T> a, LazySeq<T> b) {
if (a.isEmpty()) {
return b;
}
if (b.isEmpty()) {
return a;
}
if (a.head().compareTo(b.head()) <= 0) {
return LazySeq.cons(a.head(), () -> mergeSorted(a.tail(), b));
} else {
return LazySeq.cons(b.head(), () -> mergeSorted(a, b.tail()));
}
}
This is attempting to build against b88. Crashes in both IntelliJ and Maven.
Two things: if an explicit comparator is passed in rather than having
T be Comparable, it works. (See attachment: MergeSortSafe.java). It
also works if I replace the lambdas with explicit instantiations of
Supplier<LazySeq<T>> (see MergeSortWithoutLambdas.java).
I'm pretty sure this is a bug. I hope this is the right place to
report it. Cheers for all your hard work, guys. I hope this one gets
fixed soon.
— Samir.
More information about the lambda-dev
mailing list