Skip to content

Instantly share code, notes, and snippets.

@abrightwell
Created June 5, 2012 18:18
Show Gist options
  • Select an option

  • Save abrightwell/2876676 to your computer and use it in GitHub Desktop.

Select an option

Save abrightwell/2876676 to your computer and use it in GitHub Desktop.
NullPointerException Null Check
// Bad
try {
this.someProperty = someObject.getValue();
} catch (NullPointerException e) {
this.someProperty = someDefaultValue;
}
// Better
if (someObject != null) {
this.someProperty = someObject.getValue();
} else {
this.someProperty = someDefaultValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment