Skip to content

Commit efb5250

Browse files
vaadin-botLegioth
andauthored
fix: Explicitly check the lock when touching pendingJsInvocations (#22783) (#22794)
Explicitly check the lock when touching pendingJsInvocations Alos uses proper UI in test: this ensures that the session is available also from the inside and not only through a Mockito mock. Related to #22742 Co-authored-by: Leif Åstrand <leif@vaadin.com>
1 parent 59745bf commit efb5250

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ public void addJavaScriptInvocation(
626626
* @return a list of pending JavaScript invocations
627627
*/
628628
public List<PendingJavaScriptInvocation> dumpPendingJavaScriptInvocations() {
629+
session.checkHasLock();
629630
pendingTitleUpdateCanceler = null;
630631

631632
if (pendingJsInvocations.isEmpty()) {
@@ -683,6 +684,7 @@ public void execute() {
683684

684685
private void removePendingInvocation(
685686
PendingJavaScriptInvocation invocation) {
687+
session.checkHasLock();
686688
UIInternals.this.pendingJsInvocations.remove(invocation);
687689
if (invocationList.isEmpty() && registration != null) {
688690
registration.remove();
@@ -705,6 +707,7 @@ void onInvocationCompleted(PendingJavaScriptInvocation invocation) {
705707
*/
706708
// Non-private for testing purposes
707709
Stream<PendingJavaScriptInvocation> getPendingJavaScriptInvocations() {
710+
session.checkHasLock();
708711
return pendingJsInvocations.stream()
709712
.filter(invocation -> !invocation.isCanceled());
710713
}

flow-server/src/test/java/com/vaadin/flow/server/communication/AtmospherePushConnectionTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.vaadin.flow.component.UI;
3939
import com.vaadin.flow.server.MockVaadinSession;
4040
import com.vaadin.flow.server.communication.AtmospherePushConnection.State;
41+
import com.vaadin.tests.util.MockUI;
4142

4243
/**
4344
* @author Vaadin Ltd
@@ -52,9 +53,10 @@ public class AtmospherePushConnectionTest {
5253

5354
@Before
5455
public void setup() throws Exception {
55-
UI ui = Mockito.spy(new UI());
5656
vaadinSession = new MockVaadinSession();
57-
Mockito.when(ui.getSession()).thenReturn(vaadinSession);
57+
vaadinSession.lock();
58+
UI ui = new MockUI(vaadinSession);
59+
vaadinSession.unlock();
5860
broadcaster = Mockito.mock(Broadcaster.class);
5961
resource = Mockito.mock(AtmosphereResource.class);
6062
Mockito.when(resource.getBroadcaster()).thenReturn(broadcaster);

0 commit comments

Comments
 (0)