Skip to content

Instantly share code, notes, and snippets.

@WonderBeat
Created July 16, 2013 07:21
Show Gist options
  • Save WonderBeat/6006523 to your computer and use it in GitHub Desktop.
Save WonderBeat/6006523 to your computer and use it in GitHub Desktop.
Defencive style nightmare
/**
* Extracts digits from string
* returns digits string or null if nothing found
*/
@Nullable String getDigits(String str) {
return getDigitsInternal(str)
}
/**
* Multiplies string by 2
*/
String dobleString(String str) {
if(str != null) {
return str + str;
}
return null;
}
String toUpperCase(String str) {
if(str != null) {
return str.toUpper();
}
return null;
}
public static void main() {
String str = "abc"; // <-- contains no digits
String digits = getDigits(str);
sendWithTcp(toUpperCase(doubleString(digits))); // <-- NPE in send() method
}
@WonderBeat
Copy link
Author

Happy Debug mode is ON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment