Skip to content

Consider inheritance when checking models #85

Open

Description

@msridhar

We should be able to leverage inheritance when writing models for librarys. E.g., Collections.toArray(T[]) is specified to throw an NPE whenever the parameter is null. Right now, we need to add a model for Collections.toArray, ArrayDeque.toArray, LinkedList.toArray, etc. to get full safety. It'd be nice to just add a model for Collections.toArray and then catch this for any overriding method. Would need to be careful about performance when implementing this.

Activity

  1. kageiit commented on Dec 18, 2017

    @kageiit
    Contributor

    @msridhar we are seeing the word performance thrown around a lot during many tickets failed against nullaway, but we dont seem to have a concrete way to measure this. Can we setup a profiling sample using jmh in this repo that can we run as part of travis and give us numbers on what the performance change looks like on PRs? or atleast a way for us to run manually?

  2. msridhar commented on Dec 18, 2017

    @msridhar
    ContributorAuthor

    @kageiit opened #87 on benchmarking / profiling. Not sure we can trust numbers from Travis, but at least for running locally it should be useful.

  3. vlsi commented on Oct 22, 2026

    @vlsi
    Contributor

    Triage update on current master (5023d67): this is still open for parameter models, and done for other kinds of models.

    With JSpecify mode and the JSpecify JDK models (JSpecifyJDKModels, on by default with JSpecifyExperimental), linkedList.toArray(nullArray) is reported, because those models annotate the parameter on LinkedList and ArrayList themselves. Without them, it is not reported.

    Should this issue stay open for the parameter models, or is the JSpecify JDK models coverage enough to close it? If it stays open, the question for the parameter models is the same one #445 settled for return models: whether an inherited model may apply to an overriding method that is annotated.

    Reproducer (NullAway 5023d67, JDK 21)

    Flags: -XepOpt:NullAway:AnnotatedPackages=com.uber (standard mode). The same source is not reported with -XepOpt:NullAway:JSpecifyMode=true -XDaddTypeAnnotationsToSymbol=true -XepOpt:NullAway:JSpecifyExperimental=true -XepOpt:NullAway:JSpecifyJDKModels=false, and is reported when JSpecifyJDKModels is left on.

    package com.uber;
    import java.util.ArrayList;
    import java.util.LinkedList;
    class Test {
      void viaLinkedList(LinkedList<String> l) {
        String[] a = null;
        l.toArray(a); // expected: passing @Nullable parameter 'a' ...; observed: no diagnostic
      }
      void viaArrayList(ArrayList<String> l) {
        String[] a = null;
        l.toArray(a); // expected: passing @Nullable parameter 'a' ...; observed: no diagnostic
      }
    }

    The same call through Collection<String> or ArrayDeque<String> is reported, because both have exact models. l.toArray(null) does not compile on JDK 11 and later (ambiguous with toArray(IntFunction)), hence the local.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions