On Tue, 8 Sep 2026 15:13:56 GMT, John Hendrikx <[email protected]> wrote:

>> modules/javafx.base/src/main/java/com/sun/javafx/binding/ListenerList.java 
>> line 119:
>> 
>>> 117:         }
>>> 118:         finally {
>>> 119:             if (!wasLocked) {
>> 
>> Is it possible to write a regression test for the logic error?
>
> Many tests already fail if you get this wrong (it was a bad commit on my 
> side), it perhaps wasn't 5000 tests that failed, but it was a lot :)
> 
> I think there even already is a targetted test (but it is so fundamental that 
> many others will fail as well).

I digged deeper into the vetoing and the `logNonConvergence` the last days and 
I really like it. 
Digging into the code, I have one question. I wrote a test which demonstrates 
my question:


    @Test
    void test() {
        SimpleIntegerProperty property = new SimpleIntegerProperty(0);
        List<Change> firstListenerChanges = new ArrayList<>();
        List<Change> secondListenerChanges = new ArrayList<>();
        List<Change> thirdListenerChanges = new ArrayList<>();

        property.addListener((_, old, current) -> {
            System.out.println("L1");
            firstListenerChanges.add(new Change("L1", old, current));

            if (current.intValue() == 2) {
                property.set(1);
            }
        });
        property.addListener((_, old, current) -> {
            System.out.println("L2");
            secondListenerChanges.add(new Change("L2", old, current));
        });
        property.addListener((_, old, current) -> {
            System.out.println("L3");
            thirdListenerChanges.add(new Change("L3", old, current));

            if (current.intValue() == 1) {
                System.out.println("Set 2");
                property.set(2);
                System.out.println("Set 3");
                property.set(3);
            }
        });

        property.set(1);

        assertEquals(3, property.get());
        assertConsistentChangeSequence(firstListenerChanges, 0, 3, Set.of(0, 1, 
2, 3));
        assertConsistentChangeSequence(secondListenerChanges, 0, 3, Set.of(0, 
1, 2, 3));
        assertConsistentChangeSequence(thirdListenerChanges, 0, 3, Set.of(0, 1, 
2, 3));
    }


It prints out:

L1
L2
L3
Set 2
L1
L1
Oct 12, 2026 5:52:27 PM com.sun.javafx.binding.ListenerList logNonConvergence
WARNING: IntegerProperty [value: 1] was modified during the invocation of 
multiple listeners, and the values set do not seem to be converging; the 
listener 
test.javafx.beans.ObservableValueTest$$Lambda/0x000000005826df70@2a7686a7 
changed the value from 1 to 2, which was then reset to 1 by another listener; 
to avoid this warning ensure listeners are not making conflicting updates, or 
avoid changing the value in listeners

Set 3
L1


Shouldn't listener 2 (L2) and L3 also be notified in that case?

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1081#discussion_r4249953443

Reply via email to