If a devise of real property in a will fails by reason of the death of the devisee in the lifetime of the testator or by reason of the devise being contrary to law or otherwise incapable of taking effect, the real property shall, unless a contrary intention appears in the will, be taken to be included in the residuary devise (if any) contained in the will.