Skip to content

Use constructor injection for @ConfigProperty and qualified fields - #74

Merged
ThoSap merged 1 commit into
mainfrom
use-constructor-injection-for-config-properties
Oct 6, 2026
Merged

ThoSap merged 1 commit into
mainfrom
use-constructor-injection-for-config-properties

Conversation

@ThoSap

@ThoSap ThoSap commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Checkstyle failed on PasswordFingerprintService.secretName, because a @ConfigProperty field must be package-private for Quarkus field injection, and VisibilityModifier rejects a non-private field. This PR moves every @ConfigProperty and qualified @Inject field to constructor injection with @RequiredArgsConstructor.

  • lombok.config: Lombok copies @ConfigProperty and @Readiness to the parameter of the generated constructor. Without this, the constructor parameter has no qualifier and Quarkus injects the wrong value or fails.
  • PasswordFingerprintService, Given, ClusterConnectionReconcilerTest: the @ConfigProperty fields are now private final. The @SuppressWarnings("NullAway.Init") on them is gone, because the constructor sets them.
  • PostgreSQLInstanceReadinessCheckTest, ClusterConnectionReconcilerErrorTest: @Inject fields replaced with private final fields. @InjectMock stays a field, because Quarkus supports it on fields only.
  • PasswordFingerprintServiceTest: passes the Secret name to the constructor instead of setting the field.

IntelliJ warning "Private access modifier usage is not recommended for Quarkus CDI members"

IntelliJ shows this warning on the private final @ConfigProperty fields. It is a false positive:

  • Lombok copies the annotation, so it stays on the field too. Quarkus reads the constructor parameter.
  • AutoInjectFieldProcessor, which adds the implicit @Inject to a field with a qualifier, skips final fields. ArC also ignores @Inject on a final field. The code is the same in Quarkus 3.35.3, 3.40.1, and main.
  • The CDI reference names constructor injection as one of the two ways to avoid reflection on private members.

Tests

checkstyleMain and checkstyleTest pass. The 48 tests of PasswordFingerprintServiceTest, PostgreSQLInstanceReadinessCheckTest, ClusterConnectionReconcilerTest, ClusterConnectionReconcilerErrorTest, and RoleReconcilerTest (which uses Given) pass. I did not run the full suite locally.

Lombok copies `@ConfigProperty` and `@Readiness` to the generated constructor,
so the fields can be `private final`. Quarkus never injects into a final
field, so the IDE warning about private CDI members does not apply to them.

Assisted-by: Claude:claude-opus-5-5
@ThoSap ThoSap added the enhancement New feature or request label Oct 6, 2026
@ThoSap ThoSap self-assigned this Oct 6, 2026
@ThoSap
ThoSap merged commit 31430e4 into main Oct 6, 2026
7 of 8 checks passed
@ThoSap
ThoSap deleted the use-constructor-injection-for-config-properties branch October 6, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant