@@ -269,17 +269,28 @@ private void copyDataStreamToResponse(HttpServletResponse response, ByteArrayInp
269269 FileCopyUtils .copy (buffer , response .getOutputStream ());
270270 }
271271
272- public void uploadLicense (User sw360User , MultipartFile file , boolean overwriteIfExternalIdMatches , boolean overwriteIfIdMatchesEvenWithoutExternalIdMatch ) throws IOException , TException {
273- final HashMap <String , InputStream > inputMap = new HashMap <>();
272+ public void uploadLicense (User sw360User , MultipartFile file , boolean overwriteIfExternalIdMatches , boolean overwriteIfIdMatchesEvenWithoutExternalIdMatch )
273+ throws IOException , TException {
274+
275+ if (file == null || file .isEmpty ()) {
276+ throw new BadRequestClientException ("Unable to upload license file. File is null or empty." );
277+ }
274278
275279 if (!PermissionUtils .isUserAtLeast (UserGroup .ADMIN , sw360User )) {
276- throw new BadRequestClientException ("Unable to upload license file. User is not admin" );
280+ throw new BadRequestClientException ("Unable to upload license file. User is not admin. " );
277281 }
282+
283+ final HashMap <String , InputStream > inputMap = new HashMap <>();
284+ Throwable primaryThrowable = null ;
285+
278286 try (InputStream inputStream = file .getInputStream ()) {
279287 ZipTools .extractZipToInputStreamMap (inputStream , inputMap );
280288 LicenseService .Iface sw360LicenseClient = getThriftLicenseClient ();
281289 final LicsImporter licsImporter = new LicsImporter (sw360LicenseClient , overwriteIfExternalIdMatches , overwriteIfIdMatchesEvenWithoutExternalIdMatch );
282290 licsImporter .importLics (sw360User , inputMap );
291+ } catch (Throwable t ) {
292+ primaryThrowable = t ;
293+ throw t ;
283294 } finally {
284295 IOException closeFailure = null ;
285296 for (InputStream in : inputMap .values ()) {
@@ -293,11 +304,16 @@ public void uploadLicense(User sw360User, MultipartFile file, boolean overwriteI
293304 }
294305 }
295306 }
307+
296308 if (closeFailure != null ) {
297- throw closeFailure ;
309+ if (primaryThrowable != null ) {
310+ primaryThrowable .addSuppressed (closeFailure );
311+ } else {
312+ throw closeFailure ;
313+ }
298314 }
299315 }
300- }
316+ }
301317
302318 public RequestSummary importOsadlInformation (User sw360User ) throws TException {
303319 LicenseService .Iface sw360LicenseClient = getThriftLicenseClient ();
0 commit comments