StackOverflowError in recursive Subscription.unsubscribe
Johan Vos
johan.vos at gluonhq.com
Wed Aug 13 10:06:17 UTC 2025
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 at 26-ea
/javafx.util.Subscription.lambda$and$0(Subscription.java:103)
at javafx.base at 26-ea
/javafx.util.Subscription.lambda$and$0(Subscription.java:103)
at javafx.base at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250813/dc3e2ce0/attachment.htm>
More information about the openjfx-dev
mailing list