summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJuuso Valli <juuso@vaadin.com>2014-04-16 14:47:32 +0300
committerVaadin Code Review <review@vaadin.com>2014-04-23 13:37:18 +0000
commit2e58e97e5297c0e0c718df52ba1c4b30742f3c03 (patch)
treeddad512e4de546448e08e3c5c7785a50966e0b99 /server
parenteeb956bc645a9c2aa3714747b7889e40bcca4d5f (diff)
downloadvaadin-framework-2e58e97e5297c0e0c718df52ba1c4b30742f3c03.tar.gz
vaadin-framework-2e58e97e5297c0e0c718df52ba1c4b30742f3c03.zip
Fix findUI throwing NullPointerException when extending Vaadin (#13556)
findUI sometimes threw a NPE when the session wasn't set but the UI ID was. Doesn't occur in normal use, just when doing custom things with requestStart/requestEnd or runPendingAccessTasks Change-Id: Id7733567923fa30dcab4946c43b73200c2a0fac2
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/VaadinService.java2
-rw-r--r--server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java31
2 files changed, 32 insertions, 1 deletions
diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java
index b96e284e6e..ce9badaf98 100644
--- a/server/src/com/vaadin/server/VaadinService.java
+++ b/server/src/com/vaadin/server/VaadinService.java
@@ -982,7 +982,7 @@ public abstract class VaadinService implements Serializable {
// Get UI id from the request
String uiIdString = request.getParameter(UIConstants.UI_ID_PARAMETER);
UI ui = null;
- if (uiIdString != null) {
+ if (uiIdString != null && session != null) {
int uiId = Integer.parseInt(uiIdString);
ui = session.getUIById(uiId);
}
diff --git a/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java
index 62befdc516..c3b2d6b1d4 100644
--- a/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java
+++ b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java
@@ -20,8 +20,15 @@ import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.shared.ui.ui.UIConstants;
+import com.vaadin.ui.UI;
public class VaadinPortletServiceTests {
@@ -188,4 +195,28 @@ public class VaadinPortletServiceTests {
assertThat(widgetset,
is("com.vaadin.portal.gwt.PortalDefaultWidgetSet"));
}
+
+ @Test
+ public void findUIDoesntThrowNPE() {
+ try {
+ ReentrantLock mockLock = Mockito.mock(ReentrantLock.class);
+ when(mockLock.isHeldByCurrentThread()).thenReturn(true);
+
+ WrappedSession emptyWrappedSession = Mockito
+ .mock(WrappedSession.class);
+ when(emptyWrappedSession.getAttribute("null.lock")).thenReturn(
+ mockLock);
+ VaadinRequest requestWithUIIDSet = Mockito
+ .mock(VaadinRequest.class);
+ when(requestWithUIIDSet.getParameter(UIConstants.UI_ID_PARAMETER))
+ .thenReturn("1");
+ when(requestWithUIIDSet.getWrappedSession()).thenReturn(
+ emptyWrappedSession);
+
+ UI ui = sut.findUI(requestWithUIIDSet);
+ Assert.assertNull("Unset session did not return null", ui);
+ } catch (NullPointerException e) {
+ Assert.fail("findUI threw a NullPointerException");
+ }
+ }
}