java:S3306 false positive on MicroProfile Config injection

Sonarqube configuration

  • Developer Edition
  • Version 8.9.8 (build 54436)

Problem description

Eclipse MicroProfile Config specification allows only field injection. Constructor injection is not available.
Exemple :

    private String someUrl;

So I think that the rule java:S3306 " Constructor injection should be used instead of field injection" is not relevant in that case.

Otherwise, as I’m using this in an ejb Singleton annotated @Startup, I can’t turn the default constructor ‘private’ because it raise an exception :

[INFO] [ERROR   ] CWWKZ0004E: Une exception s'est produite lors du démarrage de l'application XXX. Le message d'exception était : EJB class com.mycompany.MyEJB must have a public constructor that takes no parameters


We don’t turn that rule on by default because we recognize that its application is not universal. Perhaps you want to deactivate it from your profile?


It should be an acceptable solution :grin:
I will pass it at “information” level just as an education purpose. Thanks !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.