NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

Exluded field annotations (sometimes) ignored when also used on a constructor

Open talios opened this issue 6 years ago • 3 comments

An interesting case, which I'm trying to track why it occurs on some of my code, but not others.

I have com.google.inject.Inject configured under -XepOpt:NullAway:ExcludedFieldAnnotations and have some code that looks like:

public class Someclass {
  @Inject ServiceA serviceA;

  @Inject
  public Someclass(ServiceB serviceb) {
    ...
  }
}

and NullAway complains on the constructor, that serviceA is not initialised, when Guice will actually inject the constructor arguments, then set the injected fields correctly.

This doesn't appear to occur on all of my modules, but on those it does, it seems to always happen - is there anything I could look at as to why this might trigger?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project smx3.archiving: Compilation failure
[ERROR] /Users/amrk/IdeaProjects/Something.java:[63,10] [NullAway] initializer method does not guarantee @NonNull fields archiveProvisioningService, archivingService, eventStoreLogSearchService, lookupService, dslContext, notificationService are initialized along all control-flow paths (remember to check for exceptions or early returns).
[ERROR]     (see http://t.uber.com/nullaway )

talios avatar Jun 26 '18 03:06 talios

Hi @talios,

First of all, really sorry this bug report went without response for almost a full month, entirely my fault.

Unfortunately, I just tried to repro the issue, and was unsuccessful (see the test cases added in #192 ). Are you still getting this issue on the most recent version of NullAway? (note: 0.5.0 should be available later today and will match the current master). If you have a small full repro case that you can share with us, that would be awesome.

lazaroclapp avatar Jul 24 '18 21:07 lazaroclapp

@lazaroclapp all good - things get away with us at times. I'll recheck our code where I was hitting it, and will try with 0.5.0 and report back. If I can reproduce, will try and extract into a separate/small project.

talios avatar Jul 25 '18 01:07 talios

@talios this has been open for some time; have you ever been able to reproduce? If not, maybe we can close?

msridhar avatar May 04 '21 16:05 msridhar