summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2019-06-25 15:03:09 +0300
committerZhe Sun <31067185+ZheSun88@users.noreply.github.com>2019-06-25 15:03:09 +0300
commit3652c3a8f1ed7fc8f6e27fb2242027732fa41404 (patch)
tree5806889243c9385e542f81a4766ddcb1b0e250b9
parent973731763c2aa7138584646c06385c4e8340a7ac (diff)
downloadvaadin-framework-3652c3a8f1ed7fc8f6e27fb2242027732fa41404.tar.gz
vaadin-framework-3652c3a8f1ed7fc8f6e27fb2242027732fa41404.zip
Fixing upload handler error handling (#11630)
* Fixing upload handler error handling For some reason stream variable cleanup did not use UI.getCurrent(), despite current UI was set earlier in handleRequest, what I see specifically for this purpose. So I chanted this. This will address also issue #7289 Furthermore there was TODO in handle request about error handling. I interpreted this to refer to possible corner case, that UI is not found via session. In this case it is more appropriate throw UploadException and abort, than lat NPE happen. * Fixing exception type
-rw-r--r--server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java8
1 files changed, 6 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
index dbb394cea2..64e0df1b06 100644
--- a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
+++ b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
@@ -269,13 +269,17 @@ public class FileUploadHandler implements RequestHandler {
session.lock();
try {
UI uI = session.getUIById(Integer.parseInt(uiId));
+ if (uI == null) {
+ throw new IOException(
+ "File upload ignored because the UI was not found and stream variable cannot be determined");
+ }
+ // Set UI so that it can be used in stream variable clean up
UI.setCurrent(uI);
streamVariable = uI.getConnectorTracker()
.getStreamVariable(connectorId, variableName);
String secKey = uI.getConnectorTracker().getSeckey(streamVariable);
if (secKey == null || !secKey.equals(parts[3])) {
- // TODO Should rethink error handling
return true;
}
@@ -456,7 +460,7 @@ public class FileUploadHandler implements RequestHandler {
try {
// Store ui reference so we can do cleanup even if connector is
// detached in some event handler
- UI ui = connector.getUI();
+ UI ui = UI.getCurrent();
boolean forgetVariable = streamToReceiver(session, inputStream,
streamVariable, filename, mimeType, contentLength);
if (forgetVariable) {