(a) In all cases in which a lien shall be filed under the provisions of this subchapter by any person other than a contractor, it shall be the duty of the contractor to defend at his or her own expense any action brought thereupon. During the pendency of the action, the owner may withhold from the contractor the amount of money for which the lien shall be filed.
(b)
(1) In case of judgment against the owner or his or her property upon the lien, the owner shall be entitled to deduct from any amount due by him or her to the contractor the amount of the judgment and costs.
(2) If the owner shall have settled with the contractor in full, he or she shall be entitled to recover back from the contractor any amount so paid by the owner for which the contractor was originally liable.