Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextUtils.isEmpty(null) returns false

Tags:

What am I missing? This doesn't make any sense:

screenshot of Android Studio

Why is TextUtils.isEmpty(null) returning false?

like image 640
tir38 Avatar asked Oct 04 '16 21:10

tir38


People also ask

What is TextUtils isEmpty?

isEmpty(CharSequence str) Returns true if the string is null or 0-length. static boolean. isGraphic(CharSequence str) Returns whether the given CharSequence contains any printable characters.

Does TextUtils isEmpty check null?

Yes, TextUtils. isEmpty(string) is preferred. TextUtils will always return a boolean value. In code, the former simply calls the equivalent of the other, plus a null check.


1 Answers

I faced this same issue while writing my unit test. The problem was I had following setting in my Gradle:

testOptions {
    unitTests.returnDefaultValues = true
}

By default android code returned default value, while running my unit tests. Just get rid of that and you should be fine.

like image 130
LoveForDroid Avatar answered Sep 24 '22 17:09

LoveForDroid