Skip to content

refactor: improve dependency injection and error handling in async producer managers - #2071

Merged
lbroudoux merged 2 commits into
microcks:masterfrom
kishore08-07:async-producer-managers
May 4, 2026
Merged

lbroudoux merged 2 commits into
microcks:masterfrom
kishore08-07:async-producer-managers

Conversation

@kishore08-07

Copy link
Copy Markdown
Contributor

Description

This PR addresses 13 SonarQube maintainability and reliability violations across three classes in minions/async/src/main/java/io/github/microcks/minion/async/producer/.

  • Replaces all @Inject field injections with constructor injection
  • Reduces cognitive complexity in triggerAsyncMockMessages by extracting the inner binding dispatch into a private helper method
  • guards unsafe Optional access
  • replaces broad Throwable catches with Exception, and returns an empty
    collection instead of null.
  • A ProducerDependencies holder class is introduced to keep the ProducerManager constructor within the 7-parameter limit while preserving backward compatibility for existing tests via a suppressed 9-parameter constructor.
  • passes mvn spotless:check -pl minions/async.

Related issue(s)

See also #2058

…ng in async producer managers

Address SonarQube maintainability and reliability issues across
ProducerManager, KafkaProducerManager and WebSocketProducerManager.

Critical:
- Extract triggerBindingMockMessage helper to reduce cognitive complexity (S3776)

Major:
- Replace field injection with constructor injection (S6813)
- Introduce ProducerDependencies to limit constructor parameters (S107)
- Guard Optional#get() with isPresent() in renderEventMessageHeaders (S3655)
- Replace Throwable with Exception in message rendering methods (S1181)
- Return Collections.emptySet() instead of null (S1168)

Minor:
- Remove unnecessary braces in lambda expressions (S1126)
- Replace unused exception variable with '_' (S6910)

Behaviour is unchanged.

Signed-off-by: kishore08-07 <[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.

Thanks for this refactoring. This looks all good to me!

@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 6da76c7 into microcks:master May 4, 2026
11 of 12 checks passed
@kishore08-07
kishore08-07 deleted the async-producer-managers branch May 7, 2026 11:55
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