Moved NullAwayExample.java to libraries-3.
Updated the libraries-3 README
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user