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; return null;
} }
String fullQualifiedName = null;
String []urlSegments = url.toString().split("/"); String query = url.getQuery();
if (urlSegments.length < 1) { if (query != null && query.startsWith("fileName=")) {
if (log.isDebugEnabled()) { String[] queryParts = query.split("=", 2);
log.debug("Cannot determine the file name for the remote file"); if (queryParts.length > 1 && !queryParts[1].isEmpty()) {
fullQualifiedName = queryParts[1];
} }
return null;
} }
if (fullQualifiedName == null) {
String fullQualifiedName = urlSegments[urlSegments.length - 1]; String[] urlSegments = url.getPath().split("/");
String []fileNameSegments = fullQualifiedName.split("\\.(?=[^.]+$)"); if (urlSegments.length > 0) {
if (fileNameSegments.length != 2) { 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()) { 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; 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 (urlPathSegments.length < 2) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("URL patch segments contain less than 2 segments"); log.debug("URL patch segments contain less than 2 segments");
@ -190,7 +199,6 @@ public class FileTransferServiceHelperUtil {
return null; return null;
} }
String file = urlPathSegments[urlPathSegments.length - 1];
String artifactHolder = urlPathSegments[urlPathSegments.length - 2]; String artifactHolder = urlPathSegments[urlPathSegments.length - 2];
try { try {
FileDescriptor fileDescriptor = new FileDescriptor(); FileDescriptor fileDescriptor = new FileDescriptor();

Loading…
Cancel
Save