fixed NPE if no UploadProgress object is stored for uploadId in (#780)

Fixed NPE if no UploadProgress object is stored for uploadId in artifactUploadState.

Signed-off-by: Markus Block <markus.block@bosch-si.com>
This commit is contained in:
Markus Block
2019-01-10 14:33:02 +01:00
committed by Stefan Behl
parent da098b334b
commit 5025192844

View File

@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.ui.artifacts.upload;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
import org.eclipse.hawkbit.ui.artifacts.upload.FileUploadProgress.FileUploadStatus;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
@@ -18,6 +17,7 @@ import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
import org.springframework.util.StringUtils;
import org.vaadin.spring.events.EventBus.UIEventBus;
import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
@@ -328,11 +328,7 @@ public class UploadProgressInfoWindow extends Window {
status = STATUS_INPROGRESS;
}
item.getItemProperty(COLUMN_STATUS).setValue(status);
final String failureReason = artifactUploadState.getFileUploadProgress(fileUploadId).getFailureReason();
if (StringUtils.isNotBlank(failureReason)) {
item.getItemProperty(COLUMN_REASON).setValue(failureReason);
}
item.getItemProperty(COLUMN_REASON).setValue(getFailureReason(fileUploadId));
final long bytesRead = fileUploadProgress.getBytesRead();
final long fileSize = fileUploadProgress.getContentLength();
@@ -340,4 +336,22 @@ public class UploadProgressInfoWindow extends Window {
item.getItemProperty(COLUMN_PROGRESS).setValue((double) bytesRead / (double) fileSize);
}
}
/**
* Returns the failure reason for the provided fileUploadId or an empty
* string but never <code>null</code>.
*
* @param fileUploadId
* @return the failure reason or an empty String.
*/
private String getFailureReason(final FileUploadId fileUploadId) {
String failureReason = "";
if (artifactUploadState.getFileUploadProgress(fileUploadId) != null) {
failureReason = artifactUploadState.getFileUploadProgress(fileUploadId).getFailureReason();
}
if (StringUtils.isEmpty(failureReason)) {
return "";
}
return failureReason;
}
}