summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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");
+ }
+ }
}