fix(license): improve exception handling in uploadLicense stream cleanup#3896
Open
melbiialy wants to merge 1 commit intoeclipse-sw360:mainfrom
Open
Conversation
The uploadLicense() method in Sw360LicenseService had a critical flaw
where the original exception could be lost when stream cleanup failed.
The finally block would throw a new IOException during cleanup, replacing
and hiding the actual import failure exception, making debugging extremely
difficult.
Added null/empty file validation at the start of the method. Refactored
exception handling to use a primaryException variable that preserves the
original error. Extracted stream cleanup logic to a separate method
closeInputMapStreams() that adds close failures as suppressed exceptions
instead of replacing the primary exception.
Changed from:
finally { if (closeFailure != null) throw closeFailure; }
To:
catch (Exception e) { primaryException = e; throw e; }
finally { closeInputMapStreams(inputMap, primaryException); }
This ensures that if license import fails with "Invalid license format"
and stream close fails with "Stream already closed", both errors are
preserved with the import error as primary and close error as suppressed.
This fix improves debuggability of license upload failures and follows
Java exception handling best practices for resource cleanup.
Signed-off-by: melbiialy <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical exception handling flaw in the
uploadLicense()method where the original exception could be lost during stream cleanup failures.Problem:
The finally block would throw a new IOException during cleanup, replacing and hiding the actual import failure exception, making debugging extremely difficult.
Solution:
Changed from:
To:
Dependencies
No new dependencies added.
Issue: #3895
Suggest Reviewer
@GMishx