Hi,

The current implementation of Subscription.unsubscribe() uses recursion to
unsubscribe the chain of subscriptions. This can lead to a
StackOverflowError in case there are many chained subscriptions. Running
the following code demonstrates this:

```
    void testSubs() {
        SimpleStringProperty prop = new SimpleStringProperty("simpel");
        Subscription s = prop.subscribe(() -> {});
        for (int i = 0; i < 100000; i++) {
            Subscription t = prop.subscribe(() -> {});
            s = s.and(t);
        }
        s.unsubscribe();
    }
```

This results in
```
java.lang.StackOverflowError
at javafx.base@26-ea
/javafx.util.Subscription.lambda$and$0(Subscription.java:103)
at javafx.base@26-ea
/javafx.util.Subscription.lambda$and$0(Subscription.java:103)
at javafx.base@26-ea
/javafx.util.Subscription.lambda$and$0(Subscription.java:103)
...
```

While it's unusual (and in most cases a very bad idea) to chain that many
Subscriptions, I don't think this should give a StackOverflow Error. I
believe it is better to avoid recursion in the implementation. If people
agree, I'll file an issue for this.

- Johan

Reply via email to