Kellogg, J.:
The evidence fairly sustained the judgment against the railroad company, and no error is found to its prejudice.
It is clear that the .practice pursued by the court with reference to the defendants Burhans & Black Company and Currier was erroneous. It could not receive evidence of their liens over the objection that it was not within the pleadings and then refuse to consider such evidence in deciding the case. This procedure is not warranted by law and must destroy a judgment based upon it. (Ewald v. Poates, 107 App. Div. 242; Robinson v. N. Y. Elevated R. R. Co., 175 N. Y. 219.)
The court, therefore, erroneously found that neither the Burhans & Black Company nor Currier was' entitled to relief. Upon the facts found the Burhans & Black Company had a valid lien which was superior to the plaintiff’s lien, and the defendant Currier had a valid lien which was subsequent to the liens of the Burhans & Black Company and the plaintiff and prior to the other lienors. The judgment upon the facts found should have so provided. The court having found all of the facts in their favor and having committed an error of law in not giving them the benefit thereof, we may order the judgment which should have been granted at the trial upon the facts found. (Sayre v. State, 123 N. Y. 291; Bryant v. Turner, No. 2, 126 App. Div. 598.)
It would be useless formality, however for us to direct judgmént upon the facts found if the court erred in receiving the evidence upon which such findings are based. It, therefore, becomes important to determine whéther the trial court committed error in receiving evidence of such liens over the objection that it was inadmissible under the pleadings. Section 3402 of the Code of Civil Procedure, which was in force at the time, required that all parties other than plaintiff having liens shall be made parties, defendant, and section 3403 provides that the court may adjust and determine the equities of all the parties and the order of priority of different liens and determine all the issues raised by any defense or counter *149claim. The allegation in the complaint that each of said parties had filed a mechanic’s lien against the property on the date and for the amount stated, and the prayer for relief that all the rights, interests and priority of the plaintiff and of the defendants be ascertained and determined, and the answers of the said defendants, do not leave them in the position described in subdivision 3 of section 3403 of the Code of Civil Procedure of waiving their liens. Under that subdivision every defendant who is a lienor must set forth his lien, or he will be deemed to have waived it “ unless the lien is admitted in the complaint and not contested by another defendant.” These liens were substantially admitted in the complaint; the lienors were made parties, not as persons claiming liens, but as persons having liens, and the plaintiff sought an adjudication as to priority. The answer of each of said defendants, read in connection with the complaint which it referred to, was a sufficient allegation of their liens when objected to for the first time upon the trial. A defendant whose rights are substantially admitted in the complaint may safely rely upon that fact. He is not in a position to know, and it is not necessary for him to inquire what the status of the pleadings is between the plaintiff and other .defendants. The lien being substantially admitted by the complaint is not to be deemed controverted so as to visit upon him the penalty of subdivision 3 above unless the defendant controverts it by serving upon him an answer under section 521 of the Code of Civil Procedure challenging his rights. All parties appeared before the court for trial; the plaintiff having substantially admitted the existence of the defendants’ liens, asserted its own lien and sought the determination of' the court as to priority of liens; the defendant lienors were there to protect their priority of liens, the railroad company to question all the liens. If the railroad company had served upon the other defendant lienors an answer asking that their liens be declared invalid, that would have required the said lienors to set forth their lien in proper issuable form. In the absence of such answer the defendant lienors were entitled to introduce, their evidence and have their liens declared. The bringing of an action to foreclose a lien brings all the parties before the court, and if a lien is established the court is to distribute the fund among the lienors according to their respective rights. The judgment should, therefore, be modified as above, and *150as modified affirmed, with costs to the plaintiff against the railroad, company and with costs to the Burhans & Black Company and Currier to be paid by the respondents. '
All concurred, except Sewell, J., dissenting.
Judgment modified as per opinion, and as so modified affirmed, with costs to the plaintiff against the railroad company, and with costs to Burhans & Black Company and Currier to be paid by the respondents.