]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix possible NPE with MPR (#12040)
authorTatu Lund <tatu@vaadin.com>
Wed, 5 Aug 2020 10:00:28 +0000 (13:00 +0300)
committerGitHub <noreply@github.com>
Wed, 5 Aug 2020 10:00:28 +0000 (13:00 +0300)
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

server/src/main/java/com/vaadin/server/Page.java
server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java

index 0708a23000f2d702f976a12462d4890a359f196c..0479ee3c883caead9b229aa15b1f80f528f69811 100644 (file)
@@ -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;
     }
index 66f3dca4c55b1dc51b9733b438e08229d7f0b20b..9d68aca8986b957199fe03b2cb644e9109431a05 100644 (file)
@@ -54,6 +54,7 @@ public class ServletUIInitHandlerTest {
                     session);
             session.setCommunicationManager(communicationManager);
             session.setConfiguration(deploymentConfiguration);
+            session.setCurrent(session);
             session.addUIProvider(new UIProvider() {
 
                 @Override