aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2020-08-05 13:00:28 +0300
committerGitHub <noreply@github.com>2020-08-05 13:00:28 +0300
commitb36dc81569fffc9d12fd6648366c965bbae4000e (patch)
tree57391f6040dd7f53f9a76b5c50be917bc7a8901c /server
parent446a7680c2903d03a90e7eb869ea67ef9a23c51f (diff)
downloadvaadin-framework-b36dc81569fffc9d12fd6648366c965bbae4000e.tar.gz
vaadin-framework-b36dc81569fffc9d12fd6648366c965bbae4000e.zip
Fix possible NPE with MPR (#12040)
It is possible when Vaadin 8 is used with MPR, that ui.getCurrent().getSession() returns null. See: https://github.com/vaadin/multiplatform-runtime/issues/5
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/server/Page.java21
-rw-r--r--server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java1
2 files changed, 17 insertions, 5 deletions
diff --git a/server/src/main/java/com/vaadin/server/Page.java b/server/src/main/java/com/vaadin/server/Page.java
index 0708a23000..0479ee3c88 100644
--- a/server/src/main/java/com/vaadin/server/Page.java
+++ b/server/src/main/java/com/vaadin/server/Page.java
@@ -997,11 +997,22 @@ public class Page implements Serializable {
* set to {@code false}
*/
public URI getLocation() throws IllegalStateException {
- if (location == null && !uI.getSession().getConfiguration()
- .isSendUrlsAsParameters()) {
- throw new IllegalStateException("Location is not available as the "
- + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS
- + " parameter is configured as false");
+ if (location == null) {
+ if (uI.getSession() != null && !uI.getSession().getConfiguration()
+ .isSendUrlsAsParameters()) {
+ throw new IllegalStateException("Location is not available as the "
+ + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS
+ + " parameter is configured as false");
+ } else if (VaadinSession.getCurrent() == null) {
+ throw new IllegalStateException("Location is not available as the "
+ + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS
+ + " parameter state cannot be determined");
+ } else if (!VaadinSession.getCurrent().getConfiguration()
+ .isSendUrlsAsParameters()) {
+ throw new IllegalStateException("Location is not available as the "
+ + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS
+ + " parameter is configured as false");
+ }
}
return location;
}
diff --git a/server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java b/server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java
index 66f3dca4c5..9d68aca898 100644
--- a/server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java
+++ b/server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java
@@ -54,6 +54,7 @@ public class ServletUIInitHandlerTest {
session);
session.setCommunicationManager(communicationManager);
session.setConfiguration(deploymentConfiguration);
+ session.setCurrent(session);
session.addUIProvider(new UIProvider() {
@Override