Skip to content

Commit

Permalink
Merge pull request #202 from uhafner/check-for-null
Browse files Browse the repository at this point in the history
Replace `Nullable` with `CheckForNull`
  • Loading branch information
uhafner authored Aug 19, 2020
2 parents 76e033a + 4c1b731 commit 9ee7333
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 36 deletions.
2 changes: 1 addition & 1 deletion etc/checkstyle-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<module name="IllegalCatch"/>
<module name="IllegalImport">
<property name="illegalPkgs" value="net.jcip.annotations, javax.annotation"/>
<property name="illegalClasses" value="edu.umd.cs.findbugs.annotations.CheckForNull"/>
<property name="illegalClasses" value="edu.umd.cs.findbugs.annotations.Nullable"/>
<property name="severity" value="error"/>
</module>
</module>
Expand Down
29 changes: 26 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>edu.hm.hafner</groupId>
Expand Down Expand Up @@ -91,7 +92,7 @@
<pitest-junit5-plugin.version>0.12</pitest-junit5-plugin.version>
<maven-error-prone-plugin.version>2.8.6</maven-error-prone-plugin.version>
<error-prone.version>2.4.0</error-prone.version>
<nullaway.version>0.7.5</nullaway.version>
<nullaway.version>0.8.0</nullaway.version>
<maven-depgraph-plugin.version>3.3.0</maven-depgraph-plugin.version>
<versions-maven-plugin.version>2.7</versions-maven-plugin.version>
<revapi-maven-plugin.version>0.12.1</revapi-maven-plugin.version>
Expand All @@ -105,6 +106,16 @@

</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>${nullaway.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
Expand Down Expand Up @@ -258,7 +269,7 @@
<arg>-Xep:MethodCanBeStatic:OFF</arg>
<arg>-Xep:WildcardImport:OFF</arg>
<arg>-Xep:ThrowsUncheckedException:OFF</arg>
<arg>-Xep:NullableDereference:OFF</arg> <!-- Exception -->
<arg>-Xep:NullableDereference:OFF</arg>
</compilerArgs>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
Expand Down Expand Up @@ -461,6 +472,18 @@
<revapi.semver.ignore>
<enabled>true</enabled>
</revapi.semver.ignore>
<revapi.ignore >
<item>
<code>java.annotation.removed</code>
<annotation>@edu.umd.cs.findbugs.annotations.Nullable</annotation>
<justification>Annotation should be save to change.</justification>
</item>
<item>
<code>java.annotation.added</code>
<annotation>@edu.umd.cs.findbugs.annotations.CheckForNull</annotation>
<justification>Annotation should be save to change.</justification>
</item>
</revapi.ignore>
</analysisConfiguration>
</configuration>
<executions>
Expand Down
44 changes: 22 additions & 22 deletions src/main/java/edu/hm/hafner/util/Ensure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -194,7 +194,7 @@ private Ensure() {
* Assertions for iterables.
*/
public static class IterableCondition extends ObjectCondition {
@Nullable
@CheckForNull
private final Iterable<?> value;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand All @@ -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]);
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -740,7 +740,7 @@ public void isTrue() {
* Assertions for exceptions.
*/
public static class ExceptionCondition {
@Nullable
@CheckForNull
private final Throwable value;

/**
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/util/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/hm/hafner/util/StringContainsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/edu/hm/hafner/util/TreeString.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. */
Expand All @@ -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);

Expand Down Expand Up @@ -77,7 +77,7 @@ TreeString split(final String prefix) {
}

@VisibleForTesting
@Nullable
@CheckForNull
TreeString getParent() {
return parent;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/edu/hm/hafner/util/ArchitectureRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ee7333

Please sign in to comment.