Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Quarkus CDI injection with defaults

24 views
Skip to first unread message

Benjamin Evans

unread,
Oct 18, 2024, 11:13:51 AM10/18/24
to jspecify...@googlegroups.com
Hi folks,

Sorry if this has been covered before - I'm still getting up to speed a bit.

I have some Quarkus code with properties like this:

  @ConfigProperty(name = "rbac.retry.back-off.initial-value", defaultValue = "0.1S")
  Duration initialBackOff;

The annotation here is org.eclipse.microprofile.config.inject.ConfigProperty and given there is a default value, means that the field is guaranteed to be non-null.

Would it be possible to extend the checkers (I'm using NullAway) to account for this case and automatically detect that a CDI field with default values is @NonNull? What would be involved in this?

Thanks,

Ben
--
Ben Evans (He/Him)
Senior Principal Software Engineer & Java Champion, Red Hat Runtimes

Manu Sridharan

unread,
Oct 18, 2024, 12:15:14 PM10/18/24
to Benjamin Evans, jspecify...@googlegroups.com
Hi Ben,

From a JSpecify perspective, I think the field is in fact @NonNull.  The error you’re getting from NullAway relates to the fact that it cannot see any initialization of the field, which I don’t think JSpecify has much to say about.  NullAway does have a configuration setting to skip checking initialization of fields with certain annotations:


It doesn't yet have a way to only exclude the field from initialization checking if some attribute is present.  If you open an issue on the NullAway repo, we can discuss there.  

Best,
Manu


--
You received this message because you are subscribed to the Google Groups "jspecify-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspecify-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspecify-discuss/CANSpity5ghk7%3DxBCZ37e8bK6AA5pYoJV4Q%3DX5Pb_nvW9oHVUeg%40mail.gmail.com.

tagir....@jetbrains.com

unread,
Oct 21, 2024, 2:40:55 AM10/21/24
to jspecify-discuss
I agree that it's out of the scope of JSpecify. IntelliJ IDEA does not report this field, as it recognizes the @ConfigProperty annotation as a possible implicit write. We support tons of fields from different frameworks which could be implicitly written. @InjectSoftAssertions (AssertJ), @javax.ejb.EJB (JavaEE), @com.google.inject.Inject (Guice), @org.easymock.Mock (EasyMock), to name a few. Of course, JSpecify cannot cover all of them. In general, the semantics of annotation processing is an extralinguistic feature. So it's all about a specific static analyzer tool to recognize them.

With best regards,
Tagir Valeev

Reply all
Reply to author
Forward
0 new messages