Fix #3895: Improve exception handling in uploadLicense method#3923
Merged
GMishx merged 1 commit intoeclipse-sw360:mainfrom Apr 6, 2026
Merged
Conversation
2e0b892 to
32f522b
Compare
Contributor
|
Bro i already fixed this in #3896 |
Contributor
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. |
GMishx
requested changes
Mar 23, 2026
...-server/src/main/java/org/eclipse/sw360/rest/resourceserver/license/Sw360LicenseService.java
Outdated
Show resolved
Hide resolved
Improve exception handling in uploadLicense method eclipse-sw360#3895 Co-authored-by: Gaurav Mishra <gmishx@gmail.com> Signed-off-by: keerthi-bl <121924406+keerthi-bl@users.noreply.github.com>
9362044 to
a400165
Compare
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
Fixes #3895
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