]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make sure lock() is released in finally block
authorPer-Åke Minborg <minborg@speedment.com>
Fri, 28 Oct 2016 17:32:12 +0000 (10:32 -0700)
committerHenri Sara <hesara@vaadin.com>
Sat, 5 Nov 2016 01:18:57 +0000 (03:18 +0200)
Change-Id: I80b73b653e97904605dc62484a7448f3bfbf7227

server/src/test/java/com/vaadin/server/VaadinSessionTest.java
server/src/test/java/com/vaadin/tests/server/component/abstractsinglecomponentcontainer/RemoveFromParentLockingTest.java

index 58fb0658c5eec9ac331191466383aea1417d8daf..0310b9293d53d735972b24e4d7baa83efeff0c2d 100644 (file)
@@ -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);
                 }
index 429f6a838ffd72a66f987a260108172eb5ed2dfe..a2a25cb818169dd1d15d1bfc0e104ed4c799d979 100644 (file)
@@ -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());
         }
     }