Repository navigation
Conversation
…rn type. We had been trying to get by without, requiring users to suppress where needed. But our philosophy has shifted more toward "If you want to be able to put null in or get null out, then it needs to be `@Nullable`." This change brings us closer to upstream, which uses `@PolyNull`.
wmdietl
left a comment
There was a problem hiding this comment.
Adding the @Nullable looks good. It would be interesting to learn how many new warnings you get from the @Nullable on the return type. That would be another case for adding @PolyNull.
I do have a question about the value parameter.
|
In the PR title, should |
Realistically, the answer is likely to be "zero," just because we don't use these stubs that widely yet. Well, OK, it's not going to be "zero" because I'm going to have to update some implementations of these methods in |
"function return type" was meant to refer to the final type argument of I'll see what I can do about that as I rework the description as a whole to cover the newly broadened scope from the |
Map.merge with @Nullable on the method and function return type.Map.merge annotations.
If I make the change for our Checker Framework users, I do see errors. It's not many, simply because there I still feel OK with this PR, at least for now :) I could imagine taking a different path by avoiding |
It's redundant there, since the value type is already non-nullable. I overlooked this in #14 and noticed it only later in eisop/jdk#45.
|
We might someday care that Kotlin avoids |
|
...and a week later, we're seeing actual problems from the difference between our signatures and Kotlin's :) |
…work and Kotlin do. In contrast, for _`computeIfAbsent`_, I've kept the signature _without_ `@Nullable` on the function result type and method return type. This is far more convenient for most callers, and it just might not cause problems for anyone: Callers of `computeIfAbsent` might _always_ provide a function that elects to insert a value (as expressed by returning a non-null value). I think this gives us the signatures that we'll want for the long term for `Map`, though of course we'd revisit if we chose to include `@PolyNull`. Previously: - #14 (comment) - #19 (comment) Note that this PR excludes `java.util.Properties` because there are a number of other changes that I'm going to make to it (and then upstream).
…work and Kotlin do. In contrast, for _`computeIfAbsent`_, I've kept the signature _without_ `@Nullable` on the function result type and method return type. This is far more convenient for most callers, and it just might not cause problems for anyone: Callers of `computeIfAbsent` might _always_ provide a function that elects to insert a value (as expressed by returning a non-null value). I think this gives us the signatures that we'll want for the long term for `Map`, though of course we'd revisit if we chose to include `@PolyNull`. Previously: - #14 (comment) - #19 (comment) Note that this PR excludes `java.util.Properties` because there are a number of other changes that I'm going to make to it (and then upstream).
|
(The Kotlin problems we're seeing appear to run deeper than a mismatch between our signatures and Kotlin's, but the mismatch does appear to be part of the picture. I'm hoping to report a Kotlin bug and then link to it from here.) Backing up to I still feel OK about annotating |
I think I can envision a way: val result = concurrentMap.computeIfAbsent(key, ::unannotatedJavaFunctionThatMightReturnNull)I don't think that's likely, but it's possible (I think... I haven't tested). |
|
(I just learned of another case (this time in Java) in which someone is using |
To partially tie up this loose end: I've confirmed that the problem we were seeing will go away once we can get Kotlin to recognize our usages of If I'd been thinking, I would have tested what would happen if I were to change our signature for |
@Nullableto the method return type and to the "return-type" typeargument of
remappingFunction.We had been trying to get by without, requiring users to suppress where
needed. But our philosophy has shifted more toward "If you want to be
able to put null in or get null out, then it needs to be
@Nullable."This change brings us closer to upstream, which uses
@PolyNull.@NonNulltovalueparameter and to the "input" types argument ofremappingFunction.