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.
boolean testIsNull() {
- return Objects.isNull("foo");
+ return "foo" == 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.
boolean testIsNotNull() {
- return Objects.nonNull("foo");
+ return "foo" != 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.
long testIsNullFunction() {
- return Stream.of("foo").filter(s -> s == null).count();
+ return Stream.of("foo").filter(Objects::isNull).count();
}
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.
long testNonNullFunction() {
- return Stream.of("foo").filter(s -> s != null).count();
+ return Stream.of("foo").filter(Objects::nonNull).count();
}