Created
July 16, 2013 07:21
-
-
Save WonderBeat/6006523 to your computer and use it in GitHub Desktop.
Defencive style nightmare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Happy Debug mode is ON