javabugs:S6555 gets confused by passing NonNull argument to Nullable function

SonarQube for v2025.1 (102418)
Issue is not reported by IDE plugin.

This is basically what the code in question looks like simplified and with variable names removed. I’ve added in all the annotations shown in SonarQube.

// in C.java
// Parameter is implicitly @NonNull due to @NonNullApi on package level 
public static C from(
  // [1] Parameter a is received
  [1] A a
) {
  // [2] from is called
  // [3] value is passed as parameter a
  var b = [2][3] B.from(a);

  // The access on a value that can be null
  var aId = [7] a.getId();

  return new C(aId, b);
}

// in B.java
public static B from(
  // [4] Parameter a is received
  // parameter is marked nullable because it can be null in other contexts not shown in this example
  [4] @Nullable A a
) {
  // [5] Assuming 'a' is null
  // [6] Taking true branch
  [6] if ([5] a == null) {
    return new B(null);
  } else {
    return new B(a);
  }
}

I worked around this by changing the order such that A.getId was called before B.from instead, and Sonar stopped complaining.

Thank you for the short reproducer and apologies for the bug.

We are currently working on a fix for this category of issues, which should land in the next few weeks.

Best,