package fxtest; import java.util.concurrent.atomic.AtomicInteger; import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; public class ObjectPropertyChangeListenerBug { public static void main(final String[] args) { final ObjectProperty> itemsProperty = new SimpleObjectProperty>( FXCollections. observableArrayList()); final AtomicInteger invalidationCount = new AtomicInteger(0); final AtomicInteger changeCount = new AtomicInteger(0); itemsProperty.addListener(new InvalidationListener() { @Override public void invalidated(Observable paramObservable) { invalidationCount.incrementAndGet(); } }); itemsProperty .addListener(new ChangeListener>() { @Override public void changed( final ObservableValue> observableValue, final ObservableList oldValue, final ObservableList newValue) { changeCount.incrementAndGet(); } }); itemsProperty.set(FXCollections. observableArrayList()); assert (invalidationCount.get() == 1); assert (changeCount.get() == 1); } }