When any property is held by an officer by virtue of a writ of attachment, any person other than the defendant having a general or special property interest therein with a right to the immediate possession thereof, and, when the property so held is claimed by the defendant to be exempt from execution, the defendant may bring an action of replevin against the officer alone, or against the plaintiff in the writ of attachment, or against both, to recover the property.