Really minor quibble, but personally I think this reads better...
```
    if (ex instanceof ItemNotFoundException) {
      final ItemNotFoundReason reason = ((ItemNotFoundException) ex).getReason();
      if (reason instanceof ItemNotFoundInRepositoryReason) {
        return buildReasoning(((ItemNotFoundInRepositoryReason)reason).getRepository().getId(), ex);
      }
    }
    return null;
```