Skip to content

Fix #3895: Improve exception handling in uploadLicense method#3923

Merged
GMishx merged 1 commit intoeclipse-sw360:mainfrom
Bhawanishanker22:fix-upload-license-exception
Apr 6, 2026
Merged

Fix #3895: Improve exception handling in uploadLicense method#3923
GMishx merged 1 commit intoeclipse-sw360:mainfrom
Bhawanishanker22:fix-upload-license-exception

Conversation

@Bhawanishanker22
Copy link
Copy Markdown
Contributor

@Bhawanishanker22 Bhawanishanker22 commented Mar 16, 2026

Description

Fixes #3895

This PR fixes issue #3895 by improving exception handling in the
uploadLicense() method of Sw360LicenseService.

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

  1. Input validation

    • Added validation to ensure the uploaded file is not null or empty
      before processing.
  2. Preserve the primary exception

    • Captured the original exception thrown during license import.
    • Ensured it is rethrown so the real failure remains visible.
  3. Use suppressed exceptions for cleanup failures

    • If InputStream.close() fails after an import failure,
      the cleanup exception is attached using Throwable.addSuppressed().
    • This preserves the original error while still reporting the cleanup issue.
  4. Improved error reporting

    • If no prior exception occurred but stream closing fails,
      a clear SW360Exception is thrown indicating a cleanup failure.

Why This Fix Is Correct

This behavior aligns with Java's try-with-resources design:

  • The primary exception remains the main throwable.
  • Any close() failures are added as suppressed exceptions.
  • Logging frameworks such as SLF4J and Log4j automatically display suppressed exceptions in stack traces.

Behavior Before Fix

@melbiialy
Copy link
Copy Markdown
Contributor

Bro i already fixed this in #3896

@Bhawanishanker22
Copy link
Copy Markdown
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 GMishx added needs code review needs general test This is general testing, meaning that there is no org specific issue to check for labels Mar 23, 2026
Copy link
Copy Markdown
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change needed.

Copy link
Copy Markdown
Contributor

@keerthi-bl keerthi-bl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good!

Copy link
Copy Markdown
Member

@GMishx GMishx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go.

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>
@GMishx GMishx force-pushed the fix-upload-license-exception branch from 9362044 to a400165 Compare April 6, 2026 10:42
@GMishx GMishx merged commit 6f2c37c into eclipse-sw360:main Apr 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs code review needs general test This is general testing, meaning that there is no org specific issue to check for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improper Exception Handling in License Upload Stream Cleanup

4 participants