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

* set to {@code false} * set to {@code false}
*/ */
public URI getLocation() throws IllegalStateException { 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; return location;
} }

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

session); session);
session.setCommunicationManager(communicationManager); session.setCommunicationManager(communicationManager);
session.setConfiguration(deploymentConfiguration); session.setConfiguration(deploymentConfiguration);
session.setCurrent(session);
session.addUIProvider(new UIProvider() { session.addUIProvider(new UIProvider() {


@Override @Override

Loading…
Cancel
Save