diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-08-10 12:13:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-10 12:13:25 +0300 |
commit | 084ee81ad54d119320b051f324309932746a2556 (patch) | |
tree | be383577cd3cbf2677e630e744a1a3de3a88957d | |
parent | 47af00706b9ab5bddf63cd9ebc463c5373cda3ed (diff) | |
download | vaadin-framework-084ee81ad54d119320b051f324309932746a2556.tar.gz vaadin-framework-084ee81ad54d119320b051f324309932746a2556.zip |
Fix possible NPE with MPR (#12040) (#12066)
* 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
-rw-r--r-- | server/src/main/java/com/vaadin/server/Page.java | 21 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java | 1 |
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 925df59121..2a0c8ab83e 100644 --- a/server/src/main/java/com/vaadin/server/Page.java +++ b/server/src/main/java/com/vaadin/server/Page.java @@ -996,11 +996,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 |