NullRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!NullRules\$).*
as compiler argument.
Table of contents
IsNull
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("IsNull")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!NullRules\$IsNull).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testIsNull() {
- return ImmutableSet.of(null == "foo", Objects.isNull("bar"));
+ return ImmutableSet.of("foo" == null, "bar" == null);
}
IsNotNull
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("IsNotNull")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!NullRules\$IsNotNull).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testIsNotNull() {
- return ImmutableSet.of(null != "foo", Objects.nonNull("bar"));
+ return ImmutableSet.of("foo" != null, "bar" != null);
}
RequireNonNullElse
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("RequireNonNullElse")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!NullRules\$RequireNonNullElse).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<String> testRequireNonNullElse() {
- return ImmutableSet.of(
- MoreObjects.firstNonNull("foo", "bar"), Optional.ofNullable("baz").orElse("qux"));
+ return ImmutableSet.of(requireNonNullElse("foo", "bar"), requireNonNullElse("baz", "qux"));
}
RequireNonNullElseGet
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("RequireNonNullElseGet")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!NullRules\$RequireNonNullElseGet).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testRequireNonNullElseGet() {
- return Optional.ofNullable("foo").orElseGet(() -> "bar");
+ return requireNonNullElseGet("foo", () -> "bar");
}
IsNullFunction
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("IsNullFunction")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!NullRules\$IsNullFunction).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Predicate<String>> testIsNullFunction() {
- return ImmutableSet.of(s -> s == null, not(Objects::nonNull));
+ return ImmutableSet.of(Objects::isNull, Objects::isNull);
}
NonNullFunction
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("NonNullFunction")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!NullRules\$NonNullFunction).*
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Predicate<String>> testNonNullFunction() {
- return ImmutableSet.of(s -> s != null, not(Objects::isNull));
+ return ImmutableSet.of(Objects::nonNull, Objects::nonNull);
}