Fix #3895: Improve exception handling in uploadLicense method#3923
Open
Bhawanishanker22 wants to merge 1 commit intoeclipse-sw360:mainfrom
Open
Fix #3895: Improve exception handling in uploadLicense method#3923Bhawanishanker22 wants to merge 1 commit intoeclipse-sw360:mainfrom
Bhawanishanker22 wants to merge 1 commit intoeclipse-sw360:mainfrom
Conversation
2e0b892 to
32f522b
Compare
Contributor
|
Bro i already fixed this in #3896 |
Author
|
Thanks for addressing this. I have created a PR for the same issue. My PR is focused on preserving the original exception, adding checks for null/empty files, and adding cleanup failures as suppressed exceptions. |
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.
Description
This PR fixes issue #3895 by improving exception handling in the
uploadLicense()method ofSw360LicenseService.Previously, if an exception occurred during the license import and
another exception occurred while closing the input stream, the original
exception could be lost. This made debugging difficult because only the
stream cleanup error was visible, hiding the actual cause of the failure.
This patch ensures that the original exception is preserved while still
recording any cleanup failures.
Changes
Input validation
nullor emptybefore processing.
Preserve the primary exception
Use suppressed exceptions for cleanup failures
InputStream.close()fails after an import failure,the cleanup exception is attached using
Throwable.addSuppressed().Improved error reporting
a clear
SW360Exceptionis thrown indicating a cleanup failure.Why This Fix Is Correct
This behavior aligns with Java's
try-with-resourcesdesign:close()failures are added as suppressed exceptions.Behavior Before Fix