Skip to content

Nullness bound for unbounded wildcard in a nullness-annotated context #83

Closed

Description

@kevinb9n

[update: direct link to doc about this issue]

Consider these classes:

// what default is in effect does not matter

class Foo<T extends @Nullable Object> { … }
class Bar<T extends @Nullable NotObject> { … }

And these precise types written within a default-not-null context:

// we are in a default-not-null context

Foo<?> foo = ...
Bar<?> bar = ...

The question is: what nullness do the upper bounds of these wildcards have?

(Assuming the answer to #82 is "no", we must have the same answer in both cases.)

Activity

  1. kevinb9n commented on Dec 3, 2019

    @kevinb9n
    CollaboratorAuthor

    I have attempted to start exploring both sides of this issue in a document:
    https://docs.google.com/document/d/1HGupJjYkFs6OPjH4tQFmivNr1sPcHicaXDdMVvGfu4A/edit#

    Please direct any substantive debate into comments or direct edits of that doc.

  2. kevinb9n commented on Dec 3, 2019

    @kevinb9n
    CollaboratorAuthor

    This issue is pretty closely related to #12. Sometimes an option is to first make the decision that two issues must be decided in the same direction as each other consistently, then debate that direction. In this case I think it will make the argument way more complicated than it already is, so I'm making an attempt to have us first get a working decision for #83, then take that decision into account in getting a working decision for #12.

  3. added
    nullness
    on Dec 12, 2019
  4. kevinb9n commented on Dec 18, 2019

    @kevinb9n
    CollaboratorAuthor

    Under the current assumptions in the document, the arguments seem to be favoring making the <?> nullable-bounded aka unconstrained. (Even the arguments were split down the middle, that should still point toward matching existing eclipse/CF behavior.)

  5. kevin1e100 commented on Dec 18, 2019

    @kevin1e100
    Collaborator

    Yep I went ahead and updated the doc accordingly a few days ago.

  6. cpovirk commented on Feb 5, 2020

    @cpovirk
    Collaborator

    Copying an observation from @kevin1e100 here: Foo<@NonNull ?> would be one of the few cases (possibly the only case) in which @NonNull has an effect in a @DefaultNonNull context. Other usages of @NonNull in that context would be redundant.

    This isn't a huge deal, just a small negative worth nothing.

    (And while I'm here, I'll note that I found the need for this concept -- <? extends @NonNull Object>, to be explicit about it -- to be vanishingly small in Guava.)

  7. changed the title [-]Nullness bound for unbounded wildcard [/-] [+]Nullness bound for unbounded wildcard in a nullness-annotated context (resolved: nullable)[/+] on May 8, 2020
  8. changed the title [-]Nullness bound for unbounded wildcard in a nullness-annotated context (resolved: nullable)[/-] [+]Nullness bound for unbounded wildcard in a nullness-annotated context (working decision: nullable)[/+] on May 8, 2020
  9. added a commit that references this issue on Nov 10, 2020
  10. added
    design
    on Mar 13, 2024
  11. added this to the 0.3 milestone on Mar 27, 2024
  12. netdpb commented on Apr 9, 2024

    @netdpb
    Collaborator

    Current decision: In null-marked code, the wildcard in Foo<?> can capture nullable types (assuming the corresponding type parameter isn't bounded by a non-null type). If you want it not to capture nullable types you'd have to write Foo<? extends Object>. (Unlike type parameter declarations, bytecode does distinguish between Foo<?> and Foo<? extends Object>).

    Argument for changing: The current decision is inconsisitent with the fact that nullability must be explicit in all other type usages in null-marked code.

    However, no strong case was made for changing the decision.

    Timing: This must be decided before version 1.0 of the jar because it's mentioned in the Javadoc for @NullMarked.

    Proposal for 1.0: Finalize the current decision. If you agree, please add a thumbs-up emoji (👍) to this comment. If you disagree, please add a thumbs-down emoji (👎) to this comment and briefly explain your disagreement. Please only add a thumbs-down if you feel you can make a strong case why this decision will be materially worse for users or tool providers than an alternative.

    Results: This proposal received six 👍s and no other votes. It is finalized. I'll edit the title to reflect that.

  13. netdpb commented on May 17, 2024

    @netdpb
    Collaborator

    Decision: In null-marked code, the wildcard in Foo<?> can capture nullable types (assuming the corresponding type parameter isn't bounded by a non-null type). If you want it not to capture nullable types you'd have to write Foo<? extends Object>.

  14. changed the title [-]Nullness bound for unbounded wildcard in a nullness-annotated context (working decision: nullable)[/-] [+]Nullness bound for unbounded wildcard in a nullness-annotated context[/+] on May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    designnullness

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions