Where the complaint demands judgment for the immediate possession of the property, if the property is actually occupied, the occupant shall be made defendant in the action. If it is not so occupied, the action shall be brought against some person exercising acts of ownership thereupon, or claiming title thereto or an interest therein, at the time of the commencement of the action. Any person claiming title to, or the right to the possession of, the real property sought to be recovered, as landlord, remainderman, reversioner, or otherwise adversely to the plaintiff, may be joined as defendant.
N.Y. Real Prop. Acts. Law § 631