Moved NullAwayExample.java to libraries-3.

Updated the libraries-3 README
This commit is contained in:
Greg Martin
2020-03-16 16:55:14 -04:00
parent b60b729906
commit 0a5fbbe0e7
2 changed files with 1 additions and 0 deletions
+1
View File
@@ -12,3 +12,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m
- [Guide to the Cactoos Library](https://www.baeldung.com/java-cactoos)
- [Parsing Command-Line Parameters with Airline](https://www.baeldung.com/java-airline)
- [Introduction to cache2k](https://www.baeldung.com/java-cache2k)
- [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway)
@@ -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);
}
}