code4nothing/singlepath — pull request #14 by arialdomartini (2014-07-25 07:33:04+00:00)
Title: Quiz #3 - Smell of Null Objects

Here is a snippet of code I took (and adapted) from our production code.
Yes, it is **real code**, hence your Pull Requests could be truly accepted :beer: :beer: :beer:

```java
public String Execute(final String file) {

final String rewrittenUrl = fileHandler.getXmlFileFromFileName(file);
final String executionId = fileHandler.getExecutionIdFromFileName(file);

if ((executionId == "") || (rewrittenUrl == "")) {
return "";
}

Foo knownFoo = fooRepository.getFooByXmlFileName(rewrittenUrl);

if (knownFoo == null) {
return "";
}

return knownFoo.DoThat(file);
}
```

There are two conditional sections.

* **The first** is a [Guard Clause](http://c2.com/cgi/wiki?GuardClause) .
```java
if ((executionId == "") || (rewrittenUrl == "")) {
return "";
}

```
Now, Guard Clauses are not necessarily bad.
It would be very interesting to *deliberately* remove it, only in order to judge if the resulting code is better or worse

* The **second one** is

```
if (knownFoo == null) {
return "";
}

return knownFoo.DoThat(file);
```

To me, it smells of missing [Null Object](https://en.wikipedia.org/wiki/Null_Object_pattern), doesn't it?