Skip to content

Support richer @EnsuresNonNullIf with methods, at least for library models #1664

Description

@msridhar

This is important for handling certain JDK cases like Class.isArray(), which if it returns true, ensures that getComponentType() on the same object returns @NonNull:

https://github.com/typetools/jdk/blob/9b1958333ddd472b31fa9ad6cc1b7faf80edd664/src/java.base/share/classes/java/lang/Class.java#L844

Not modeling this leads to a lot of false positives on JUnit (with JSpecify JDK models enabled). There's a similar relationship between Queue.isEmpty() and Queue.peek() / Queue.poll(), though modeling that is more complex since a Queue can contain nulls and also isEmpty() is inherited from Collection.

Metadata

Metadata

Assignees

No one assigned

    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