Browse Source

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
tags/8.12.0.alpha1
Tatu Lund 3 years ago
parent
commit
b36dc81569
No account linked to committer's email address

+ 16
- 5
server/src/main/java/com/vaadin/server/Page.java View 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;
}

+ 1
- 0
server/src/test/java/com/vaadin/server/communication/ServletUIInitHandlerTest.java View File

@@ -54,6 +54,7 @@ public class ServletUIInitHandlerTest {
session);
session.setCommunicationManager(communicationManager);
session.setConfiguration(deploymentConfiguration);
session.setCurrent(session);
session.addUIProvider(new UIProvider() {

@Override

Loading…
Cancel
Save