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 :

    @Inject
    @ConfigProperty(name="myprj.some.url")
    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 : com.ibm.ws.container.service.state.StateChangeException: com.ibm.ws.cdi.CDIException: com.ibm.wsspi.injectionengine.InjectionException: com.ibm.ejs.container.EJBConfigurationException: EJB class com.mycompany.MyEJB must have a public constructor that takes no parameters

Hi,

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?

 
Ann

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.