Skip to content

Meta issue for constraint solver rewrite #1932

Open

Description

@msridhar

This is a meta-issue for a constraint solver rewrite for generic method inference to encompass #1585 and #1291. Right now, our solve() method to solve constraints has signature:

https://github.com/uber/NullAway/blob/b35c8ca002709b09778ad7ea1ac36a882282c505/nullaway/src/main/java/com/uber/nullaway/generics/ConstraintSolver.java#L78-L78

This needs to change in (at least) two ways:

  1. The returned Map is currently key'd on Elements corresponding to generic type variables. But as shown in Generic method inference does not support inferring different nullability for multiple calls to same generic method #1291, the same generic method may be invoked more than once in the context of a particular inference problem. So, really this should be key'd on some record datatype that includes both the Element and also the MethodInvocationTree identifying the call to the generic method.
  2. Enhance generic method inference to compute mappings from type variables to full types? #1585 discusses how in various cases it would be better to infer a complete nullness-annotated type for each value in the map. Right now the values are InferredNullability, which only gives the top-level nullability of a type. Instead, the values in the map should be fully nullness-annotated Types, including nested annotations.

This may require other changes to the solver interface, e.g., addSubtypeConstraint may also need a MethodInvocationTree parameter to identify which call generated the constraint.

Clearly the internal vars map in ConstraintSolverImpl would have to change to track all this additional information. It too would also need to incorporate invocation trees into its keys and fully-annotated types into its values.

My hope is that with a fix here for #1585 we can remove some or all of the hacks from #1473 and #1574; I would hope that the entire NestedTypeVarSubstitutionRepairVisitor type and its related "repair" code could just go away.

Beyond keeping existing tests passing, the new test cases in #1291 and #1585 should also pass after the rewrite.

Activity

  1. msridhar commented on Oct 7, 2026

    @msridhar
    ContributorAuthor
  2. subhramit commented on Oct 7, 2026

    @subhramit
    Contributor

    Commenting to allow assignment

  3. vlsi commented on Oct 9, 2026

    @vlsi
    Contributor

    Another case for the rewrite: #1947. In List.copyOf(new ArrayList<>(list)) with a List<T> whose T admits null, the inner call's type variable is itself under inference, so the constraint #1834 adds for the direct List.copyOf(list) never sees T's nullable bound. With full inferred types (#1585) the inner variable would be inferred as T.

  4. subhramit commented on Oct 19, 2026

    @subhramit
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions