If, upon the trial of an action against the commonwealth, a city, town, railroad corporation or bridge corporation, the plaintiff recovers damages for an injury to his person or property caused by reason of a defect in a public way or bridge occupied by the tracks of a company, and such company is liable for such damages under the preceding section, and has had reasonable notice to defend the action, the commonwealth, city, town, railroad corporation or bridge corporation may recover the damages, and all the costs of both plaintiff and defendant in the action from said company.
Mass. Gen. Laws ch. 161, § 90