-
Bug
-
Resolution: Fixed
-
P4
-
7
-
b130
-
x86
-
windows_xp
-
Verified
The class java.util.Objects is new for JDK 7. Its mission is to provide "null-safe or null-tolerant versions of common operations on objects."
The methods nonNull(x) have the behavior of throwing NPE if their argument is null, and returning their argument if non-null. It is very common in Java source bases for a method named nonNull(x) to have the behavior of coercing their argument to null; that is, it is generally associated with a null-tolerant rather than a null-safe behavior.
These methods should be renamed to something that makes its checking/verification behavior clear, while preserving the convenient self-return property so that it can be used in cases like:
public void fooWrapper(String s, String t) {
foo(checkNonNull(s), checkNonNull(t));
}
The methods nonNull(x) have the behavior of throwing NPE if their argument is null, and returning their argument if non-null. It is very common in Java source bases for a method named nonNull(x) to have the behavior of coercing their argument to null; that is, it is generally associated with a null-tolerant rather than a null-safe behavior.
These methods should be renamed to something that makes its checking/verification behavior clear, while preserving the convenient self-return property so that it can be used in cases like:
public void fooWrapper(String s, String t) {
foo(checkNonNull(s), checkNonNull(t));
}
- relates to
-
JDK-6889858 Add nonNull methods to java.util.Objects
- Resolved
-
JDK-8011800 Add java.util.Objects.requireNonNull(T, Supplier<String>)
- Closed