Skip to content

Naming the third nullness annotation (the one that matches the behavior of unannotated code) #32

Closed as not planned

Description

@kevinb9n

We have seemed fairly comfortable with @Nullable and @NotNull (the latter being a shorthand for @NotNullable), but oy, the third one.

The word "legacy" should be involved; we have never come up with something more appropriate. It is the nullness that all Java types have by default before someone goes through and annotates. Admittedly, people will probably use it (rarely) for special cases with non-legacy code, but we think we want to at least discourage that.

I think we also don't want to talk about it as being more closely related to @Nullable than to @NotNull; its relationship to these two should be symmetric. It represents indecision between the two. Conservative analysis treats it more like @Nullable when assigning from, but more like @NotNull when assigning to; lenient analysis would have it the other way around.

Names

@LegacyNull / @DefaultLegacyNull
@LegacyNullness / @DefaultLegacyNullness
@NullableLegacy / @DefaultNullableLegacy (sorts/groups better)
@NullUnchecked / @DefauiltNullUnchecked (same)
@SchroedingersNull

Activity

  1. donnerpeter commented on Jun 20, 2019

    @donnerpeter
    Collaborator

    Cases like Map.get might be rare among declarations, but are quite prominent usage-wise, and the word "legacy" in such core an API might scare or confuse people. How about something more neutral, e.g. "Unknown" or "Unspecified" or "Any"?

  2. kevinb9n commented on Jun 20, 2019

    @kevinb9n
    CollaboratorAuthor

    You are right. After saying "it should involve the word legacy", I made the list of names and ended up thinking of @NullUnchecked, and now I'm growing to like it a lot. As an adjective in prose, "null-unchecked" or (when context is clear) "unchecked".

    I believe the connection to the "unchecked warnings" developers are familiar with actually might be a good one: it's another case of a type conversion where the types are not truly assignable but we let you make the type conversion anyway.

    Does anyone dislike this name?

  3. cushon commented on Jun 20, 2019

    @cushon
    Collaborator

    The analogy to unchecked is interesting. One potential disadvantage is that it already has a specific meaning / baggage. I also see parallels with rawtypes: aren't legacy nullable types raw with respect to nullness information?

  4. eaftan commented on Jun 20, 2019

    @eaftan

    I like something like @UnknownNullness. It is descriptive and expresses program semantics.

  5. kevinb9n commented on Jun 20, 2019

    @kevinb9n
    CollaboratorAuthor

    The more rare the word, the stronger the connection should have to be for us to want to use it. The generics concept of "raw" is more parallel, but it's a more unusual word so we should be convinced it's "a lot" more parallel.

    We think there's virtually no reason to ever use a raw type (in the generics sense) aside from compatibility and ~3 very narrow edge cases. Would we say the same for this? I thought we would, and that was behind my preference for "legacy", but now I'm moving away from that thanks to things like Map.get.

    The word "unchecked", root "check", feels pretty basic/common. We describe the systems that use our annotation as "checkers". In some sense, this annotation is akin to telling those checkers to back off a bit on what they do. The more accurate that description is then the better this name is.

    That the nullness is "unknown" is something this shares in common with parametric nullness. The difference, I think, is that we're fine with saying that "parametric is not assignable to not-null", full stop, just like nullable is not assignable to not-null, whereas with legacy/unknown/unchecked/whatever, we're willing to make accommodations. (And similarly with "nullable is not assignable to parametric".)

  6. donnerpeter commented on Jun 21, 2019

    @donnerpeter
    Collaborator

    "Unchecked" for me implies some specific behavior expectations from checkers, and I thought we didn't intend to prescribe how they should work. If combined with more specific annotations (in spirit of @PolyNull), "unchecked" could be wrong, because such declarations would still be checked, just in a more sophisticated way.

    This name also seems to imply that the annotations are there mostly for checkers, and not e.g. for documentation or other purposes. This might be fine, I'm just not totally sure it is.

  7. kevinb9n commented on Jun 21, 2019

    @kevinb9n
    CollaboratorAuthor

    Thanks for bringing that up. You're right, avoiding seeming to dictate what a checker should do is important, and that should even have an effect on how things are named. So this is a negative for @Unchecked.

    The following may seem weird, but I think it is possible that there is much less of a problem with implying what checkers should not do than there is with implying what they should. The latter part I think we might agree solidly that we need to avoid, but the first part might not be harmful and even be virtuous in making sure library owners are able to annotate properly. I don't know.

    (In these discussions I think we will lapse into "and the checkers we imagine will do this" over and over. Perhaps it is inevitable that we have to have some imagined checker to shape our thoughts around, and maybe it will be enough if we remember to repeatedly ask ourselves "okay, but how much of that actually needs to be required of checkers?)

  8. changed the title [-]Naming the legacy nullness annotation[/-] [+]Naming the third nullness annotation (the one that matches the behavior of unannotated code)[/+] on Jun 21, 2019
  9. kevinb9n commented on Jun 21, 2019

    @kevinb9n
    CollaboratorAuthor

    Resolving this probably depends on resolving #32. (EDIT: ha, I meant #33)

  10. wmdietlGC commented on Jun 21, 2019

    @wmdietlGC
    Collaborator

    I don't like @Unchecked for the reasons @donnerpeter gives.
    @UnknownNullness seems better.
    Some other options: @JavaNullness, @ClassicNullness, @StandardNullness, or @MachineNullness. But they all have their downsides.

  11. cushon commented on Jun 21, 2019

    @cushon
    Collaborator

    @UnknownNullness is looking OK to me too.

  12. kevinb9n commented on Jun 21, 2019

    @kevinb9n
    CollaboratorAuthor

    Hmm, "unknown" used to always be on the list, and then there was some reason on Monday that seemed clear to me it could be ruled out. Now I don't know why that was. Back on the table.

  13. kevinb9n commented on Jun 26, 2019

    @kevinb9n
    CollaboratorAuthor

    We seem to be converging on @NullnessUnknown.

    (Should I still make a case for @NullUnknown?)

  14. stephan-herrmann commented on Aug 2, 2019

    @stephan-herrmann

    In my experience words like "unknown" will easily entail questions like: "why doesn't the tool know? Can't it figure it out?" etc. At Eclipse we had similar fights with the word "potential", where users are confused whether the danger depends on (a) control flow, (b) instantiation of a generic type, (c) some nullable value (which could still be different from null 😄) etc. pp.

    From that experience I tend to be explicit about what is the source of uncertainty. In the case here: it's unspecified.

    OTOH, could s.o. please point me to the discussion, why this concept (which surely is necessary for the semantics) must have an explicit expression in the syntax? To me it feels a bit like requesting a syntax like List<#RAW>, where actually List says the same already.

  15. wmdietlGC commented on Aug 2, 2019

    @wmdietlGC
    Collaborator

    The discussion of why we make the third state explicitly expressible can be found here: #2

  16. 25 remaining items

  17. wmdietlGC commented on Apr 3, 2020

    @wmdietlGC
    Collaborator

    #27 discussed @LessEnforced as a separate concept from @NullnessUnspecified.

  18. cpovirk commented on Apr 6, 2020

    @cpovirk
    Collaborator

    If we can't find a name that serves both use cases, we should also consider shifting the focus to what you call the "unspecifiable" case. My thinking:

    • The case of "I don't want to annotate this yet" might come up a lot when users don't want to annotate whole methods or classes (for which users would use declaration annotations), but...
    • I don't think users will commonly need to annotate only some of the types in a single method signature (for which they would use type annotations). (And if they do, we might supply them with ways to do that besides by using a @NullnessUnspecified type annotation.)

    So maybe we end up with a declaration annotation like @AnnotatedForNullness(false) but a type-use annotation like @NullnessUnspecifiable.

  19. mernst commented on Apr 6, 2020

    @mernst
    Contributor

    It sounds like you are in agreement that we need to distinguish the cases of:

    • I don't want to annotate this yet.
    • I have considered this method and its semantics cannot be precisely captured by the currnt version of Jspecify.

    For the former, a declaration rather than type annotation for this is a nice solution.

    For the latter, just "unspecifiable" is a misleading name. The semantics is not unspecifiable, it's just unspecifiable by this version of Jspecify.

  20. cpovirk commented on Apr 13, 2020

    @cpovirk
    Collaborator

    Switching gears:

    I forget whether we have previously discussed using @Nullable for this but with an element/method/value, as in @Nullable(weWouldLikeToDoBetterThanOutrightNullableButJspecifyIsLettingUsDown = true).

    The reason that I thought of this is that it could help with #100 (by making @Nullable @NullnessUnspecified impossible). But I don't think that should be a significant motivation.

    What we might like more is that it "hides" the "unspecified" case better than a top-level annotation does. After all, we expect that case to be rare. And users who do need that case have surely already seen @Nullable, so they might understand this new annotation as "nullable, but ...." We can still hold out hope that all we really need to provide is @DefaultNonNull and @Nullable: Such a simple API makes it easy for users to get started, and it gives us some breathing room to add other nullness annotations down the line (@PolyNull? @EnsuresNonNull?).

    On the other hand, putting the "unspecified" case into @Nullable is in some ways the opposite of hiding it: I would have to look into how IDEs handle autocompletion for annotations, but we might be inadvertently thrusting the "unspecified" case in front of users who are just trying to type @Nullable.

    (Another way to attempt the "hiding" goal (but not to help with #100) is to make this third annotation a nested type enclosed by @Nullable: @Nullable.WeWouldLikeToDoBetterThanOutrightNullableButJspecifyIsLettingUsDown. This might be better or worse than the approach of using an annotation element, depending on IDE autocompletion, Javadoc rendering, and probably other factors.)

  21. cpovirk commented on Apr 13, 2020

    @cpovirk
    Collaborator

    If we want to think about an annotation element or nested type, we should also think more about whether we would use those features for possible future additions -- like using it for @PolyNull.

    Would we want it to be possible to express onlyJointly and weWouldLikeToDoBetterThanOutrightNullableButJspecifyIsLettingUsDown together? Probably not. That's an argument for not doing both as annotation elements. Not that anyone was proposing doing even one of them that way until just now :)

  22. kevin1e100 commented on Apr 13, 2020

    @kevin1e100
    Collaborator
  23. cpovirk commented on Sep 23, 2020

    @cpovirk
    Collaborator

    Switching gears again: When will users first be forced to understand unspecified nullness? Often, it will happen when they encounter an error message that mentions it. For example:

    error: incompatible types: @Nullable Map<@NullnessUnspecified Foo, @NullnessUnspecified Bar> cannot be converted to Map<Foo, Bar>

    In Kotlin-like terms, that's saying:

    Type mismatch: inferred type is Map<Foo!, Bar!>? but Map<Foo, Bar> was expected

    The appearance of @NullnessUnspecified in error messages changes how I feel about the long name:

    • Before: If people should rarely write @NullnessUnspecified in source code, we probably don't mind making them write a long name.

    • After: If people may see @NullnessUnspecified frequently in error messages, then we may worry more about the length. In particular, I'm sad that @NullnessUnspecified is so noisy when it is never the cause of the failure -- at least in "lenient mode." Look back at the error message above: @NullnessUnspecified is the most prominent but least important part! (That's arguably made even sadder by the fact that the token "@NullnessUnspecified" never appears in the source file I'm imagining.)

    Possible solutions (some of which require action only by tool authors, not spec authors):

    1. Lenient-mode tools could hide @NullnessUnspecified from their output altogether. The downside: This will eventually confuse someone: "Why can I return a @Nullable T from this method that returns T [which secretly means @NullnessUnspecified T] but not from this other method that returns T [which means 'just T']?" This confusion would not exist if we were honest and said "@NullnessUnspecified T" in the first place. Similarly, users may be confused when they get a NullPointerException from dereferencing an object that their tools say is of type "String" (when the tools mean "@NullnessUnspecified String"). @NullnessUnspecified is already complicated, given that it's the default for unannotated code, so I worry about making it more complicated.

    2. Tools could print error messages in "Kotlin style" -- that is, by printing ! and ? instead of annotations. The downside: This style is less familiar to some users (though more familiar to others). And somehow, users need to understand the mappings @Nullable <-> ? and @NullnessUnspecified <-> ! (unlike in pure Kotlin, which uses ? for both source code and error messages). (Additionally, I don't love the use of ! for "unspecified": To me, ! suggests "not null" (for which Kotlin uses !!). Maybe tools would pick a different symbol (~, ¿, ...) but at the cost of familiarity to Kotlin users.)

    3. We could pick a shorter name for the annotation. The downside: Not only is the name less clear in source, it is less clear in error messages -- which, again, is when many users will encounter it for the first time.

    Another thing to recall is that we haven't fully settled whether a @NullnessUnspecified type annotation will even exist [edit: #137]. Suppose for a moment that it does not:

    • In one way, that simplifies things: We can say whatever we want in error messages, since there will be no equivalent source code that we would want them to correspond to.

    • In another way, it complicates things: No matter what we pick for our error messages (@NullnessUnspecified, unspecified, [@Nullable?], @???, !, ...), users who want to understand it can no longer just look up the class with that name. (And note that symbols like ? are particularly hard to query for in your favorite search engine. Tools can at least try to help by linking to useful documentation.)

  24. kevin1e100 commented on Sep 28, 2020

    @kevin1e100
    Collaborator

    @NullnessUnspecified is so noisy when it is never the cause of the failure

    Thanks for observing this.

    To me, ! suggests "not null"

    That is in fact what it meant in Spec# I believe. I've at times used !?, FWIW, but am not claiming it's a great solution.

    It may not be popular, but besides String!? there does seem to be another reasonable solution: just String could be used to mean @NullnessUnspecified String / String!? in error messages as long as both other options, @NonNull String / String!! and @Nullable String / String?, are always made explicit. This would remove "unspecified" clutter as desired and is consistent with the observation that

    the token "@NullnessUnspecified" never appears in the source file I'm imagining.

    I understand that this would take us away from Kotlin's error messages and is incompatible with the desire to generally write String!! as String. Instead, this solution would leverage "unspecified" as the default-default (so should still be reasonably intuitive to Java users).

    The other thing I'll say is that while good error messages will be important, I suspect it's probably out of scope for us to specify error messages exactly. So while I support the effort to make sure tools can produce reasonable messages, I also think we want to be careful not to wade too far into the area: seems likely to me that tools will want some room for experimentation.

  25. cpovirk commented on Sep 28, 2020

    @cpovirk
    Collaborator

    On the topic of using symbols for types, I opened #129 and left a reply there.

  26. added this to the Post-1.0 milestone on Oct 13, 2021
  27. kevinb9n commented on Sep 20, 2022

    @kevinb9n
    CollaboratorAuthor

    Reopen if we reverse course on #137.

  28. modified the milestones: Post-1.0, 0.3 on Dec 2, 2022
  29. added
    design
    on Mar 13, 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