diff --git a/libraries/pom.xml b/libraries/pom.xml index b5340d1ebb..af300657b0 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -435,7 +435,23 @@ reflections ${reflections.version} - + + com.uber.nullaway + nullaway + 0.3.0 + + + org.codehaus.plexus + plexus-compiler-javac-errorprone + 2.8 + + + + com.google.errorprone + error_prone_core + 2.1.3 + @@ -552,6 +568,47 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5 + + javac-with-errorprone + true + 1.8 + 1.8 + true + + + com.uber.nullaway + nullaway + 0.3.0 + + + + + + -XepExcludedPaths:(.*)/test/.*|(.*)/streamex/.* + -XepOpt:NullAway:AnnotatedPackages=com.baeldung.nullaway + + + + + org.codehaus.plexus + plexus-compiler-javac-errorprone + 2.8 + + + + com.google.errorprone + error_prone_core + 2.1.3 + + + + diff --git a/libraries/src/main/java/com/baeldung/nullaway/NullAwayExample.java b/libraries/src/main/java/com/baeldung/nullaway/NullAwayExample.java new file mode 100644 index 0000000000..f3db1d2df9 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/nullaway/NullAwayExample.java @@ -0,0 +1,24 @@ +package com.baeldung.nullaway; + +import com.baeldung.distinct.Person; + +public class NullAwayExample { + + /* + * 1- NullAway will warn about yearsToRetirement method + * 2- Uncomment @Nullable in printAge and NullAway will warn about this method + * 3- Add a standard null check to be NullAway compliant + * 4- Build will be SUCCESS + */ + + static Integer getAge(/*@Nullable*/ Person person) { + return person.getAge(); + } + + Integer yearsToRetirement() { + Person p = null; + // ... p never gets set correctly... + return 65 - getAge(p); + } + +} \ No newline at end of file