Skip to content

chore: #2058 Guard Optional access with isPresent() before get() - #2064

Merged
lbroudoux merged 1 commit into
microcks:masterfrom
Heyy-Himanshuu:chore/2058-optional-isPresent-checks
May 4, 2026
Merged

lbroudoux merged 1 commit into
microcks:masterfrom
Heyy-Himanshuu:chore/2058-optional-isPresent-checks

Conversation

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor

Sonar flagged four call sites that invoke Optional#get() without a preceding presence check (rule java:S3655). Any of these would throw NoSuchElementException at runtime if the Optional is empty. Each site is now guarded using the codebase's existing convention of Optional<T> xxxOpt = ...; if (xxxOpt.isPresent()) { ... }.

Description

  • minions/async — KafkaProducerManager#renderEventMessageHeaders (L226): wrap header value extraction in an isPresent guard so headers with no values are simply skipped instead of crashing the producer.
  • webapp — TestRunnerService#runTests (L200): if a TestCaseResult references an operation that no longer exists on the service, log a warning and skip that test case rather than aborting the entire test run with NoSuchElementException.
  • webapp — ExamplesExporter#exportHeaders (L174): wrap header value extraction in an isPresent guard so headers with no values are omitted from the exported document instead of crashing the export.
  • webapp — SchemaConformanceAssertion#assertResponse (L63): if no WSDL resource is available for a SOAP service, log a warning and return AssertionStatus.FAILED with a clear error message rather than crashing the assertion.
  • Happy path is unchanged in every case; only the previously unreachable empty-Optional path now degrades gracefully.
  • mvn spotless:check -pl minions/async,webapp passes locally.

Related issue(s)

See also #2058

Sonar flagged four call sites that invoke Optional#get() without a
preceding presence check, any of which would throw a runtime
NoSuchElementException if the Optional is empty (rule java:S3655).
Each site is now guarded using the codebase's existing convention of
'Optional<T> xxxOpt = ...; if (xxxOpt.isPresent()) { ... }'.

- minions/async KafkaProducerManager#renderEventMessageHeaders (L226):
  wrap header value extraction in an isPresent guard so headers with
  no values are simply skipped instead of crashing the producer.
- webapp TestRunnerService#runTests (L200): if a TestCaseResult
  references an operation that no longer exists on the service, log
  a warning and skip that test case rather than aborting the entire
  test run with NoSuchElementException.
- webapp ExamplesExporter#exportHeaders (L174): wrap header value
  extraction in an isPresent guard so headers with no values are
  omitted from the exported document instead of crashing the export.
- webapp SchemaConformanceAssertion#assertResponse (L63): if no WSDL
  resource is available for a SOAP service, log a warning and return
  AssertionStatus.FAILED with a clear error message rather than
  crashing the assertion.

The happy path is unchanged in every case; only the previously
unreachable empty-Optional path now degrades gracefully.

Signed-off-by: Git-HimanshuRathi <[email protected]>

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome! Thanks a lot! LGTM.

@lbroudoux lbroudoux added kind/task java Pull requests that update Java code labels May 4, 2026
@lbroudoux lbroudoux added this to the 1.15.0 milestone May 4, 2026
@lbroudoux
lbroudoux merged commit b900f5b into microcks:master May 4, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code kind/task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants