On Sat, 27 Jan 2024 15:23:50 GMT, Philippe Altherr <d...@openjdk.org> wrote:

>> 8324797: Code example in JavaDoc of ObservableValue#when doesn't compile
>
> I did a quick search to see if there other instances of the same problem 
> under [jfx/modules...](https://github.com/openjdk/jfx/blob/master/modules/). 
> I didn't find any but I noticed that 
> [here](https://github.com/openjdk/jfx/blob/37d7561c390f706b9e711dd535580fe5ae76e879/modules/javafx.base/src/main/java/javafx/beans/value/ObservableValue.java#L160)
>  and 
> [here](https://github.com/openjdk/jfx/blob/37d7561c390f706b9e711dd535580fe5ae76e879/modules/javafx.base/src/main/java/javafx/beans/value/ObservableValue.java#L191)
>  in the same file you have the same issue and avoid it by using a `var`, 
> which looks cleaner. My fix should probably do the same.
> 
> Below is the current code of the example. None of the calls to `setValue` 
> compile.
> 
> 
>      ObservableValue<Boolean> condition = new SimpleBooleanProperty(true);
>      ObservableValue<String> longLivedProperty = new 
> SimpleStringProperty("A");
>      ObservableValue<String> whenProperty = longLivedProperty.when(condition);
> 
>      // observe whenProperty, which will in turn observe longLivedProperty
>      whenProperty.addListener((ov, old, current) -> 
> System.out.println(current));
> 
>      longLivedProperty.setValue("B");  // "B" is printed
> 
>      condition.setValue(false);
> 
>      // After condition becomes false, whenProperty stops observing 
> longLivedProperty; condition
>      // and whenProperty may now be eligible for GC despite being observed by 
> the ChangeListener
> 
>      longLivedProperty.setValue("C");  // nothing is printed
>      longLivedProperty.setValue("D");  // nothing is printed
> 
>      condition.setValue(true);  // longLivedProperty is observed again, and 
> "D" is printed

@paltherr Can you enable GitHub actions for your repo so that the next time you 
push a commit GitHub will run them? To do this, go to the "Actions" page in 
your repo and press the green "I understand my workflows..." button. It's very 
unlikely to be a problem for this sort of PR, but we ask everyone to do that.

> I have enabled workflows. I have also filed an issue but it looks like this 
> will go through a review of its own: review ID : 9076496 :-( In retrospect, I 
> should have added a link to this PR.

I took care of the bug. It is now visible as 
[JDK-8324797](https://bugs.openjdk.org/browse/JDK-8324797). You can update this 
PR title with the bug ID and move this PR out of draft.

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

PR Comment: https://git.openjdk.org/jfx/pull/1325#issuecomment-1913187928
PR Comment: https://git.openjdk.org/jfx/pull/1325#issuecomment-1913259106

Reply via email to