Fix throwing NullPointerException when getting a fileName with a query param.

new-master
Nipuni Kavindya 4 weeks ago
parent 1e88b2f785
commit d9a43f7efc

@ -143,24 +143,35 @@ public class FileDownloaderServiceProvider {
}
return null;
}
String []urlSegments = url.toString().split("/");
if (urlSegments.length < 1) {
if (log.isDebugEnabled()) {
log.debug("Cannot determine the file name for the remote file");
String fullQualifiedName = null;
String query = url.getQuery();
if (query != null && query.startsWith("fileName=")) {
String[] queryParts = query.split("=", 2);
if (queryParts.length > 1 && !queryParts[1].isEmpty()) {
fullQualifiedName = queryParts[1];
}
return null;
}
String fullQualifiedName = urlSegments[urlSegments.length - 1];
String []fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)");
if (fileNameSegments.length != 2) {
if (fullQualifiedName == null) {
String[] urlSegments = url.getPath().split("/");
if (urlSegments.length > 0) {
fullQualifiedName = urlSegments[urlSegments.length - 1];
}
}
if (fullQualifiedName != null) {
String[] fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)");
if (fileNameSegments.length == 2) {
return fileNameSegments;
} else {
if (log.isDebugEnabled()) {
log.debug("Error encountered when constructing file name");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Error encountered when constructing file name");
log.debug("Cannot determine the file name for the remote file");
}
return null;
}
return fileNameSegments;
return null;
}
/**

@ -183,6 +183,15 @@ public class FileTransferServiceHelperUtil {
return fileDescriptorResolvedFromRelease;
}
String file = urlPathSegments[urlPathSegments.length - 1];
String query = downloadUrl.getQuery();
if (query != null && query.startsWith("fileName=")) {
String[] queryParts = query.split("=", 2);
if (queryParts.length > 1 && !queryParts[1].isEmpty()) {
file = queryParts[1];
}
}
if (urlPathSegments.length < 2) {
if (log.isDebugEnabled()) {
log.debug("URL patch segments contain less than 2 segments");
@ -190,7 +199,6 @@ public class FileTransferServiceHelperUtil {
return null;
}
String file = urlPathSegments[urlPathSegments.length - 1];
String artifactHolder = urlPathSegments[urlPathSegments.length - 2];
try {
FileDescriptor fileDescriptor = new FileDescriptor();

Loading…
Cancel
Save