From 734d99d669e41855e57e491df612923bbaa731db Mon Sep 17 00:00:00 2001 From: =?utf8?q?Per-=C3=85ke=20Minborg?= Date: Fri, 28 Oct 2016 10:32:12 -0700 Subject: [PATCH] Make sure lock() is released in finally block Change-Id: I80b73b653e97904605dc62484a7448f3bfbf7227 --- .../com/vaadin/server/VaadinSessionTest.java | 7 +++- .../RemoveFromParentLockingTest.java | 40 ++++++++++--------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/server/src/test/java/com/vaadin/server/VaadinSessionTest.java b/server/src/test/java/com/vaadin/server/VaadinSessionTest.java index 58fb0658c5..0310b9293d 100644 --- a/server/src/test/java/com/vaadin/server/VaadinSessionTest.java +++ b/server/src/test/java/com/vaadin/server/VaadinSessionTest.java @@ -156,8 +156,11 @@ public class VaadinSessionTest implements Serializable { // when we get here httpSessionLock.lock();// simulating servlet container's // session lock - mockService.fireSessionDestroy(session); - httpSessionLock.unlock(); + try { + mockService.fireSessionDestroy(session); + } finally { + httpSessionLock.unlock(); + } } catch (InterruptedException e) { throw new RuntimeException(e); } diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractsinglecomponentcontainer/RemoveFromParentLockingTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractsinglecomponentcontainer/RemoveFromParentLockingTest.java index 429f6a838f..a2a25cb818 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractsinglecomponentcontainer/RemoveFromParentLockingTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractsinglecomponentcontainer/RemoveFromParentLockingTest.java @@ -47,19 +47,21 @@ public class RemoveFromParentLockingTest { }; session.getLockInstance().lock(); + try { + UI ui = new UI() { + @Override + protected void init(VaadinRequest request) { + } + }; + ui.setSession(session); + + VerticalLayout layout = new VerticalLayout(); + ui.setContent(layout); + return layout; + } finally { + session.getLockInstance().unlock(); + } - UI ui = new UI() { - @Override - protected void init(VaadinRequest request) { - } - }; - ui.setSession(session); - - VerticalLayout layout = new VerticalLayout(); - ui.setContent(layout); - - session.getLockInstance().unlock(); - return layout; } @Test @@ -71,11 +73,11 @@ public class RemoveFromParentLockingTest { try { target.addComponent(testComponent); throw new AssertionError( - "Moving component when not holding its sessions's lock should throw"); + "Moving component when not holding its sessions's lock should throw"); } catch (IllegalStateException e) { Assert.assertEquals( - "Cannot remove from parent when the session is not locked.", - e.getMessage()); + "Cannot remove from parent when the session is not locked.", + e.getMessage()); } } @@ -104,12 +106,12 @@ public class RemoveFromParentLockingTest { try { lockedComponent.addComponent(notLockedComponent); throw new AssertionError( - "Moving component when not holding its sessions's lock should throw"); + "Moving component when not holding its sessions's lock should throw"); } catch (IllegalStateException e) { Assert.assertEquals( - "Cannot remove from parent when the session is not locked." - + " Furthermore, there is another locked session, indicating that the component might be about to be moved from one session to another.", - e.getMessage()); + "Cannot remove from parent when the session is not locked." + + " Furthermore, there is another locked session, indicating that the component might be about to be moved from one session to another.", + e.getMessage()); } } -- 2.39.5