Skip to content

fix: check Optional.isPresent() before calling get() in DocxGenerator (#3721)#1

Open
ADITYA-CODE-SOURCE wants to merge 8 commits into
mainfrom
fix/issue-3721-docxgenerator-optional-bug
Open

fix: check Optional.isPresent() before calling get() in DocxGenerator (#3721)#1
ADITYA-CODE-SOURCE wants to merge 8 commits into
mainfrom
fix/issue-3721-docxgenerator-optional-bug

Conversation

@ADITYA-CODE-SOURCE

Copy link
Copy Markdown
Owner

Fixes eclipse-sw360#3721 - DocxGenerator crashes with NoSuchElementException when template file is missing

Bug

In DocxGenerator.generateOutputFile(), the code was calling .get() on the Optional before checking .isPresent(). This caused a raw NoSuchElementException instead of the intended SW360Exception with a helpful "Could not load the template" message.

Fix

Reordered the code to check isPresent() first before calling .get():

  • Line 110: Moved xwpfDocument = new XWPFDocument(...) inside the if (docxTemplateFile.isPresent()) block
  • Line 132: Same fix for the REPORT case
    This ensures proper error handling when the template file is missing or fails to load.

- Add 10 LicenseDB configuration constants to SW360Constants.java
- Update sw360.properties in 3 locations
- Add LicenseDBConstantsTest.java with unit tests
- Fix CI: Configure CouchDB for single-node operation

This is Phase 1 of LicenseDB integration for GSoC 2026.

Signed-off-by: ADITYA-CODE-SOURCE <adityavishe67@gmail.com>
- Add LICENSEDB to ConfigFor enum in sw360.thrift
- Add LICENSEDB_ID constant to SW360Constants
- Add LicenseDBConfig.java: OAuth and connection configuration
- Add LicenseDBRestClient.java: OAuth2 client credentials flow
- Add LicenseDBService.java: License and obligation sync logic
- Add LicenseDBController.java: Admin REST endpoints

This implements the core OAuth/M2M integration with LicenseDB.

Signed-off-by: ADITYA-CODE-SOURCE <adityavishe67@gmail.com>
- Use constructor injection instead of RestTemplateBuilder
- Fix property prefix to match sw360.properties
- Use Spring's auto-configured RestTemplate bean

Signed-off-by: ADITYA-CODE-SOURCE <adityavishe67@gmail.com>
- Add COUCHDB_CLUSTER_SIZE=1 to ensure single-node mode
- Add health check for CouchDB container
- Use -s flag for curl to suppress error output
- Add quotes around values for JSON compatibility
- Add || true to prevent step failure on errors

Signed-off-by: Aditya Vishe <adityavishe67@gmail.com>
Fixes eclipse-sw360#3721

The generateOutputFile() method was calling .get() on Optional
before checking .isPresent(), causing NoSuchElementException when
the template file is missing. Now checks isPresent() first and throws
proper SW360Exception with helpful message.
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.

Bug: DocxGenerator crashes with NoSuchElementException when template file is missing

1 participant