Found something very odd when programming my Android mobile app today. I am aware that I should not provide a null path for Picasso to load. Hence defensive statements in my code to make sure that Picasso would not get to load a null path. But somehow my app was still crashing, with the following error:
java.lang.IllegalArgumentException: Path must not be empty
And the error was pointing to the line where the Picasso call was located:
Picasso.get().load(“null image path”);
Even when this line would not be run, which I have checked, it was still giving me problem. Turns out that my defensive statement allowed non-null image path to happen first, as below:
if (imgPath != null || !(imgPath.isEmpty()) { Picasso.get().load(imgPath).into(imageView); } else { Picasso.get().load(placeholder).into(imageView); }
If I swap the defensive statement around, such that imgPath == null is checked first, then my app will run okay. Very odd. Anyone kind enough to explain to me what was that about?