Replacing these assertions would take the form of the following validation:
if (rodzic == null) throw new MyValidationException("rodzic cannot be null"); if (rodzic.rodzic == null) throw new MyValidationException("rodzic.rodzic cannot be null"); return rodzic.getBrat(); Note that there's a distinction between throwing an Exception and an Error - Exceptions are meant to be caught and handled farther up, while Errors indicate a situation that you can't recover from. For example, you might consider a defining and using a MyValidationError if the failed check is irrecoverable.