RFR: 8255248: NullPointerException in JFXPanel due to race condition in HostContainer [v3]
Michael Strauß
mstrauss at openjdk.org
Fri Jul 21 17:10:59 UTC 2023
On Thu, 20 Jul 2023 10:12:09 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> Due to transient datatype of scenePeer, it can become null which can result in NPE in scenarios where scene is continuously been reset and set, which warrants a null check, as is done in other places for the same variable.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> Check FXEnabled initially
After looking at the class for a bit longer and seeing how its state is read and mutated on different threads, it might be a better approach to enforce serialized code execution in all cases. This might be done as follows:
1. Remove all `volatile` modifiers from the fields of the class. (Also, make `disableCount` an `int` field.)
2. Mark all non-private methods which are entry points into the class with the `synchronized` modifier. Private methods should not be marked with `synchronized`.
3. Wrap code in all other entry points (lambdas, anonymous implementations) in a `synchronized` block that synchronizes on the `JFXPanel` instance.
If done correctly, no method of the class will ever run concurrently with another method of the class, and the memory effects of `synchronized` will ensure that we can always see the latest field values. What do you think about this approach?
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1178#issuecomment-1646004694
More information about the openjfx-dev
mailing list