As programmers, we probably use strings more than any other type of data structure. The cross-language String environment is characterized by shared vocabulary and well-established concepts. And it is especially important to follow these established naming conventions when it comes to null strings vs empty strings (and blank strings).
With Apache Commons StringUtils and Hibernate Validator Constraints, two popular and widely adapted projects established a de facto definition for a blank string:
“A blank String is a CharSequence that is empty (""), null or whitespace only.”
While recently investigating a bug in one of our systems, I stumbled upon a slight divergent and unexpected string handling in AssertJ, a fluent assertions framework for Java. This AssertJ misbehaviour has the potential to lead to severe troubles – which is why I consider it to be a bug. As it turns out …
|
|
… passes. This is definitely not expected behaviour, since (following the common definition above) a null string is considered to be a blank string and vice versa. So if you’re used to Apache Commons StringUtils and Hibernate Validators behaviour, you want to make sure that also your tests expect the correct behaviour.
Do you know further libraries that follow a different blank string definition or if you have a different opinion about all of this, drop me a message via Mastodon!