(a) Unless an action to enforce any lien authorized by this article is commenced in a circuit court within six months after the person desiring to avail himself or herself of the court has filed his or her notice in the clerk's office, as provided in this article, the lien shall be discharged; but an action commenced by any person having a lien shall, for the purpose of preserving the same, inure to the benefit of all other persons having a lien under this article on the same property, and persons may intervene in the action for the purpose of enforcing their liens.
(b) Notwithstanding any provisions of this code to the contrary, it is an affirmative defense, or an affirmative partial defense, as the case may be, in any action to enforce a lien pursuant to this article that the owner is not indebted to the contractor or is indebted to the contractor for less than the amount of the lien sought to be perfected, when:
(1) The property is an existing single-family dwelling;
(2) The property is a residence constructed by the owner or under a contract entered into by the owner prior to its occupancy as his or her primary residence; or
(3) The property is a single-family, owner-occupied dwelling, including a residence constructed and sold for occupancy as a primary residence. This subdivision does not apply to a developer or builder of multiple residences except for the residence that is occupied as the primary residence of the developer or builder.
(c) As used in subsection (b):
(1) 'Dwelling' or 'residence' means any building or structure intended for habitation, in whole or part, and includes, but is not limited to, any house, apartment, mobile home, house trailer, modular home, factory-built home and any adjacent outbuildings.
(2) 'Outbuilding' means any building or structure which adjoins, is part of, belongs to, or is used in connection with a dwelling, and shall include, but not be limited to, any garage, shop, shed, barn or stable.