From 4c1b73120ad4b544a0f305f58aea1663a9df7471 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 19 Aug 2020 19:18:49 +0200 Subject: [PATCH] Replace `Nullable` with `CheckForNull`. `CheckForNull` is now supported by NullAway as well: See https://github.com/uber/NullAway/pull/397 --- etc/checkstyle-configuration.xml | 2 +- pom.xml | 29 ++++++++++-- src/main/java/edu/hm/hafner/util/Ensure.java | 44 +++++++++---------- .../java/edu/hm/hafner/util/PathUtil.java | 4 +- .../hm/hafner/util/StringContainsUtils.java | 6 +-- .../java/edu/hm/hafner/util/TreeString.java | 8 ++-- .../edu/hm/hafner/util/ArchitectureRules.java | 2 +- 7 files changed, 59 insertions(+), 36 deletions(-) diff --git a/etc/checkstyle-configuration.xml b/etc/checkstyle-configuration.xml index 6aea1db8..65c3103e 100644 --- a/etc/checkstyle-configuration.xml +++ b/etc/checkstyle-configuration.xml @@ -139,7 +139,7 @@ - + diff --git a/pom.xml b/pom.xml index b4ef68d8..de0a5ef6 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 edu.hm.hafner @@ -91,7 +92,7 @@ 0.12 2.8.6 2.4.0 - 0.7.5 + 0.8.0 3.3.0 2.7 0.12.1 @@ -105,6 +106,16 @@ + + + + com.uber.nullaway + nullaway + ${nullaway.version} + + + + com.github.spotbugs @@ -258,7 +269,7 @@ -Xep:MethodCanBeStatic:OFF -Xep:WildcardImport:OFF -Xep:ThrowsUncheckedException:OFF - -Xep:NullableDereference:OFF + -Xep:NullableDereference:OFF javac-with-errorprone true @@ -461,6 +472,18 @@ true + + + java.annotation.removed + @edu.umd.cs.findbugs.annotations.Nullable + Annotation should be save to change. + + + java.annotation.added + @edu.umd.cs.findbugs.annotations.CheckForNull + Annotation should be save to change. + + diff --git a/src/main/java/edu/hm/hafner/util/Ensure.java b/src/main/java/edu/hm/hafner/util/Ensure.java index 2ac02949..467307bf 100644 --- a/src/main/java/edu/hm/hafner/util/Ensure.java +++ b/src/main/java/edu/hm/hafner/util/Ensure.java @@ -8,8 +8,8 @@ import com.google.errorprone.annotations.FormatMethod; +import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.CheckReturnValue; -import edu.umd.cs.findbugs.annotations.Nullable; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** @@ -59,8 +59,8 @@ public static BooleanCondition that(final boolean value) { * @return an object condition */ @CheckReturnValue - public static ObjectCondition that(@Nullable final Object value, - @Nullable final Object... additionalValues) { + public static ObjectCondition that(@CheckForNull final Object value, + @CheckForNull final Object... additionalValues) { return new ObjectCondition(value, additionalValues); } @@ -73,7 +73,7 @@ public static ObjectCondition that(@Nullable final Object value, * @return an iterable condition */ @CheckReturnValue - public static IterableCondition that(@Nullable final Iterable value) { + public static IterableCondition that(@CheckForNull final Iterable value) { return new IterableCondition(value); } @@ -86,7 +86,7 @@ public static IterableCondition that(@Nullable final Iterable value) { * @return a collection condition */ @CheckReturnValue - public static CollectionCondition that(@Nullable final Collection value) { + public static CollectionCondition that(@CheckForNull final Collection value) { return new CollectionCondition(value); } @@ -100,7 +100,7 @@ public static CollectionCondition that(@Nullable final Collection value) { */ @SuppressWarnings("PMD.UseVarargs") @CheckReturnValue - public static ArrayCondition that(@Nullable final Object[] value) { + public static ArrayCondition that(@CheckForNull final Object[] value) { return new ArrayCondition(value); } @@ -113,7 +113,7 @@ public static ArrayCondition that(@Nullable final Object[] value) { * @return a string condition */ @CheckReturnValue - public static StringCondition that(@Nullable final String value) { + public static StringCondition that(@CheckForNull final String value) { return new StringCondition(value); } @@ -126,7 +126,7 @@ public static StringCondition that(@Nullable final String value) { * @return an exception condition */ @CheckReturnValue - public static ExceptionCondition that(@Nullable final Throwable value) { + public static ExceptionCondition that(@CheckForNull final Throwable value) { return new ExceptionCondition(value); } @@ -194,7 +194,7 @@ private Ensure() { * Assertions for iterables. */ public static class IterableCondition extends ObjectCondition { - @Nullable + @CheckForNull private final Iterable value; /** @@ -203,7 +203,7 @@ public static class IterableCondition extends ObjectCondition { * @param value * value of the condition */ - public IterableCondition(@Nullable final Iterable value) { + public IterableCondition(@CheckForNull final Iterable value) { super(value); this.value = value; @@ -255,7 +255,7 @@ public void isNotEmpty(final String explanation, final Object... args) { * Assertions for iterables. */ public static class CollectionCondition extends IterableCondition { - @Nullable + @CheckForNull private final Collection value; /** @@ -265,7 +265,7 @@ public static class CollectionCondition extends IterableCondition { * value of the condition */ @SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter") - public CollectionCondition(@Nullable final Collection value) { + public CollectionCondition(@CheckForNull final Collection value) { super(value); this.value = value; @@ -350,7 +350,7 @@ public void doesNotContain(final Object element, final String explanation, final * Assertions for arrays. */ public static class ArrayCondition extends ObjectCondition { - @Nullable + @CheckForNull private final Object[] values; /** @@ -361,7 +361,7 @@ public static class ArrayCondition extends ObjectCondition { */ @SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter", "PMD.ArrayIsStoredDirectly", "PMD.UseVarargs"}) @SuppressFBWarnings("EI2") - public ArrayCondition(@Nullable final Object[] values) { + public ArrayCondition(@CheckForNull final Object[] values) { super(values); this.values = values; @@ -413,7 +413,7 @@ public void isNotEmpty(final String explanation, final Object... args) { * Assertions for strings. */ public static class StringCondition extends ObjectCondition { - @Nullable + @CheckForNull private final String value; /** @@ -422,7 +422,7 @@ public static class StringCondition extends ObjectCondition { * @param value * value of the condition */ - public StringCondition(@Nullable final String value) { + public StringCondition(@CheckForNull final String value) { super(value); this.value = value; @@ -509,9 +509,9 @@ private boolean isBlank() { * Assertions for objects. */ public static class ObjectCondition { - @Nullable + @CheckForNull private final Object value; - @Nullable + @CheckForNull private final Object[] additionalValues; /** @@ -520,7 +520,7 @@ public static class ObjectCondition { * @param value * value of the condition */ - public ObjectCondition(@Nullable final Object value) { + public ObjectCondition(@CheckForNull final Object value) { this(value, new Object[0]); } @@ -534,7 +534,7 @@ public ObjectCondition(@Nullable final Object value) { */ @SuppressFBWarnings("EI2") @SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter", "PMD.ArrayIsStoredDirectly"}) - public ObjectCondition(@Nullable final Object value, @Nullable final Object... additionalValues) { + public ObjectCondition(@CheckForNull final Object value, @CheckForNull final Object... additionalValues) { this.value = value; this.additionalValues = additionalValues; } @@ -740,7 +740,7 @@ public void isTrue() { * Assertions for exceptions. */ public static class ExceptionCondition { - @Nullable + @CheckForNull private final Throwable value; /** @@ -749,7 +749,7 @@ public static class ExceptionCondition { * @param value * value of the condition */ - public ExceptionCondition(@Nullable final Throwable value) { + public ExceptionCondition(@CheckForNull final Throwable value) { this.value = value; } diff --git a/src/main/java/edu/hm/hafner/util/PathUtil.java b/src/main/java/edu/hm/hafner/util/PathUtil.java index 6f03415d..a319e5bf 100644 --- a/src/main/java/edu/hm/hafner/util/PathUtil.java +++ b/src/main/java/edu/hm/hafner/util/PathUtil.java @@ -10,7 +10,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; -import edu.umd.cs.findbugs.annotations.Nullable; +import edu.umd.cs.findbugs.annotations.CheckForNull; /** * Utilities for {@link Path} instances. @@ -228,7 +228,7 @@ public String getRelativePath(final String relative) { * * @return the absolute path */ - public String createAbsolutePath(final @Nullable String directory, final String fileName) { + public String createAbsolutePath(final @CheckForNull String directory, final String fileName) { if (isAbsolute(fileName) || StringUtils.isBlank(directory)) { return makeUnixPath(fileName); } diff --git a/src/main/java/edu/hm/hafner/util/StringContainsUtils.java b/src/main/java/edu/hm/hafner/util/StringContainsUtils.java index 3b16f61b..feb6250b 100644 --- a/src/main/java/edu/hm/hafner/util/StringContainsUtils.java +++ b/src/main/java/edu/hm/hafner/util/StringContainsUtils.java @@ -2,7 +2,7 @@ import org.apache.commons.lang3.StringUtils; -import edu.umd.cs.findbugs.annotations.Nullable; +import edu.umd.cs.findbugs.annotations.CheckForNull; /** * A simple helper class in the style of {@link StringUtils} that provides methods to check if strings contain @@ -38,8 +38,8 @@ public final class StringContainsUtils { * * @return {@code true} if any of the search CharSequences are found, {@code false} otherwise */ - public static boolean containsAnyIgnoreCase(@Nullable final CharSequence input, - @Nullable final String... searchTexts) { + public static boolean containsAnyIgnoreCase(@CheckForNull final CharSequence input, + @CheckForNull final String... searchTexts) { if (StringUtils.isEmpty(input)) { return false; } diff --git a/src/main/java/edu/hm/hafner/util/TreeString.java b/src/main/java/edu/hm/hafner/util/TreeString.java index c107d725..95fa966d 100644 --- a/src/main/java/edu/hm/hafner/util/TreeString.java +++ b/src/main/java/edu/hm/hafner/util/TreeString.java @@ -5,7 +5,7 @@ import org.apache.commons.lang3.StringUtils; -import edu.umd.cs.findbugs.annotations.Nullable; +import edu.umd.cs.findbugs.annotations.CheckForNull; /** * {@link TreeString} is an alternative string representation that saves the memory when you have a large number of @@ -19,7 +19,7 @@ public final class TreeString implements Serializable { private static final long serialVersionUID = 3621959682117480904L; /** Parent node that represents the prefix. */ - @Nullable + @CheckForNull private TreeString parent; /** {@link #parent} + {@code label} is the string value of this node. */ @@ -41,7 +41,7 @@ public final class TreeString implements Serializable { * the suffix */ @SuppressWarnings("NullAway") - TreeString(@Nullable final TreeString parent, final String label) { + TreeString(@CheckForNull final TreeString parent, final String label) { Ensure.that(parent == null || !label.isEmpty()) .isTrue("if there's a parent '%s', label '%s' can't be empty", parent, label); @@ -77,7 +77,7 @@ TreeString split(final String prefix) { } @VisibleForTesting - @Nullable + @CheckForNull TreeString getParent() { return parent; } diff --git a/src/test/java/edu/hm/hafner/util/ArchitectureRules.java b/src/test/java/edu/hm/hafner/util/ArchitectureRules.java index bb9598d5..135156e5 100644 --- a/src/test/java/edu/hm/hafner/util/ArchitectureRules.java +++ b/src/test/java/edu/hm/hafner/util/ArchitectureRules.java @@ -50,7 +50,7 @@ public final class ArchitectureRules { /** Prevents that classes use visible but forbidden API. */ public static final ArchRule NO_FORBIDDEN_ANNOTATION_USED = noClasses().should().dependOnClassesThat( - have(type(edu.umd.cs.findbugs.annotations.CheckForNull.class))); + have(type(edu.umd.cs.findbugs.annotations.Nullable.class))); /** Prevents that classes use visible but forbidden API. */ public static final ArchRule NO_FORBIDDEN_CLASSES_CALLED