The bindContentBidirectional method is completely unaware of previous content bindings and allows situations that cause the bindings to be broken or even log exceptions.
For example:
public static void main(String[] args) {
ObservableList<String> a = FXCollections.observableArrayList();
ObservableList<String> b = FXCollections.observableArrayList();
Bindings.bindContentBidirectional(a, b);
Bindings.bindContentBidirectional(a, b);
a.add("A");
System.out.println(a + " : " + b);
}
Will print:
[A, A, A, A] : [A, A, A]
When there are 3 or more lists involved, the problem can get so bad that `IndexOutOfBoundsException` is thrown somewhere in the code handling the syncing of the lists (which is caught and only logged to the console while leaving the list contents badly unsynced).
I've made a PoC that rejects circular bindings and overlapping bindings when they're detected.
For example:
public static void main(String[] args) {
ObservableList<String> a = FXCollections.observableArrayList();
ObservableList<String> b = FXCollections.observableArrayList();
Bindings.bindContentBidirectional(a, b);
Bindings.bindContentBidirectional(a, b);
a.add("A");
System.out.println(a + " : " + b);
}
Will print:
[A, A, A, A] : [A, A, A]
When there are 3 or more lists involved, the problem can get so bad that `IndexOutOfBoundsException` is thrown somewhere in the code handling the syncing of the lists (which is caught and only logged to the console while leaving the list contents badly unsynced).
I've made a PoC that rejects circular bindings and overlapping bindings when they're detected.