You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The name of the UI.accessLater() function is highly confusing. Naming-wise it's very close to the access() function, but the semantics are vastly different:
access() immediately submits given Command to run on the event queue.
accessLater() doesn't submit anything, but instead returns a SerializableRunnable which, when ran by a thread, will run a block via UI.access().
What's confusing is that the function starts with a verb (access), hinting that the function immediately accesses the UI in a thread-safe manner. That can lead to two kinds of programming errors.
First issue: it appears as if UI.getCurrent() is called from a background thread. Take a look at the following example:
At first sight, without realizing the subtle difference between UI.access() and UI.accessLater(), I see that a thread is calling UI.getCurrent() which should return null, and therefore the thread should fail with a NPE. However, something else happens: the thread actually runs the block with the session lock held.
Describe your motivation
The name of the
UI.accessLater()
function is highly confusing. Naming-wise it's very close to theaccess()
function, but the semantics are vastly different:access()
immediately submits given Command to run on the event queue.accessLater()
doesn't submit anything, but instead returns aSerializableRunnable
which, when ran by a thread, will run a block viaUI.access()
.What's confusing is that the function starts with a verb (
access
), hinting that the function immediately accesses the UI in a thread-safe manner. That can lead to two kinds of programming errors.First issue: it appears as if
UI.getCurrent()
is called from a background thread. Take a look at the following example:At first sight, without realizing the subtle difference between
UI.access()
andUI.accessLater()
, I see that a thread is callingUI.getCurrent()
which should return null, and therefore the thread should fail with a NPE. However, something else happens: the thread actually runs the block with the session lock held.The examples at https://vaadin.com/docs/latest/building-apps/presentation-layer/server-push/threads are affected by this issue.
Second issue: this innocent code actually does nothing:
Describe the solution you'd like
Rename (introduce new function, deprecate old one) the
accessLater()
to something like:wrapSafe()
toUISafeRunnable()
asSafeRunnable()
The text was updated successfully, but these errors were encountered: