Skip to content

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

Open
Bhawanishanker22 wants to merge 1 commit intoeclipse-sw360:mainfrom
Bhawanishanker22:fix-upload-license-exception
Open

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

Conversation

@Bhawanishanker22
Copy link

Description

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

@Bhawanishanker22 Bhawanishanker22 force-pushed the fix-upload-license-exception branch from 2e0b892 to 32f522b Compare March 16, 2026 15:35
@melbiialy
Copy link
Contributor

Bro i already fixed this in #3896

@Bhawanishanker22
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants