Joiner.join(Object[]) doesn't accept null but is annotated with @Nullable
See original GitHub issuea4baad35 introduces @Nullable
at Joiner.join(@Nullable Object[] parts)
but actual code would throw a NullPointerException.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why does string.Join(" ", new object[] { null, "a ... - Stack Overflow
1 Answer 1 ... If the first element of values is null, the Join(String, Object[]) method does not concatenate the elements in values...
Read more >Source code - Guava
Entry; 029import javax.annotation.CheckForNull; 030import org.checkerframework.checker.nullness.qual.Nullable; 031 032/** 033 * An object which joins pieces ...
Read more >guava/Joiner.java at master - GitHub
import javax.annotation.CheckForNull;. import org.checkerframework.checker.nullness.qual.Nullable;. /**. * An object which joins pieces of text (specified ...
Read more >@Nullable and @NotNull | IntelliJ IDEA Documentation
@Nullable and @NotNull annotations let you check nullability of a variable, parameter, or return value. They help you control contracts ...
Read more >Avoid Check for Null Statement in Java - Baeldung
Learn about the Null Object Pattern and how to implement it in Java ... the null contract through the @Nullable and @NonNull annotations....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@xihongshi6 In this situation, the right thing to do is to annotate the array like so:
Here, it tells us that the array itself (the
[]
part) can be null, whereas the elements inside cannot.Likewise, to say that both the array itself and its elements can be null, one would do this:
I agree that it is ambiguous! But I think it’s a limitation of how arrays and annotations work with each other in Java.
If you have any more Guava questions, may I suggest posting them over at StackOverflow? I look at the <kbd>guava</kbd> tag there often, so if you post with that tag, then I’ll be likely to see it. Alternatively, if you have any questions that are just Java-related, post them under the <kbd>java</kbd> tag (I don’t monitor questions with that tag), or send me an email. You can find my email address on my GitHub profile. 😃
@xihongshi6 I don’t know about others, but it’s a rule that I understand anyway.
All it is saying is the array cannot be null, but any of the objects in the array can be null.
The reason why is because the
@Nullable
annotation is annotating theObject
part of the array, rather than the[]
part.So this is allowed:
But this is not allowed:
I hope this helps. 😃