NullRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!NullRules\$).* as compiler argument.

Table of contents
  1. IsNull
  2. IsNotNull
  3. RequireNonNullElse
  4. RequireNonNullElseGet
  5. IsNullFunction
  6. NonNullFunction

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.

 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();
   }

Copyright © 2017-2024 Picnic Technologies BV