Generally speaking, if a person sells a property without first offering it to the owner of the neighboring property, the neighbor can approach Bet Din (the Rabbinical Court) and demand the sale's revocation. The rule of "Bar Masra" dictates that a prospective seller of property must first offer the land or building to the neighbor before selling it to a third party, and if he did not, the neighbor can demand that the sale be annulled so that he can purchase the property.
There are, however, a number of exceptions to this rule, as discussed by the Shulhan Aruch (Hoshen Mishpat, 175). Firstly, if a house was sold to somebody in need of a home, such as a person whose house burned down, Heaven forbid, then the neighbor cannot demand the sale's revocation. Since the person who purchased the home is in dire need of a place to live, this buyer takes precedence over the neighbor, who already has a home and seeks merely to expand his assets (Rama on Hoshen Mishpat, 49.)
Furthermore, if the individual sells his property due to an immediate need for cash, and the buyer produced the money up front while the neighbor would need time to secure a loan, Bet Din does not revoke the sale. Here, too, one of the parties involved has a particular need that overrides the general preference afforded to the owner of the neighboring property. (Hoshen Mishpat, 43)
Another case in which the rule of "Bar Masra" does not apply is where the neighbor wishes to purchase the property for somebody else, such as his child or colleague. The rule of "Bar Masra" was enacted due to the unique benefit the neighbor could potentially derive from purchasing an adjoining property. Therefore, if he does not plan on using the property himself but rather to purchase it for somebody else, he is not given preference over other prospective buyers. (Hoshen Mishpat, 22)
Finally, if the seller wishes to give the property for the purpose of a Mitzva, such as to serve as a synagogue, Yeshiva or charitable organization, the neighbor cannot demand the sale's revocation. (Hoshen Mishpat, 55)
The authorities disagree as to whether the law of "Bar Masra" applies when somebody rents the adjoining property. May the renter demand the annulment of the sale of the neighboring property, or is this Halacha restricted to cases where the neighbor owns the adjoining property? The Shulhan Aruch rules that only one who owns the neighboring property can demand the sale's revocation, whereas the Rama (Rabbi Moshe Isserles, Poland, 1525-1572) maintains that even a person renting a house can demand the revocation of the sale of a neighboring house. In such a case, therefore, one must consult with a competent Halachic authority for guidance. (Hoshen Mishpat, 60)
Summary: If a person sold his property without first offering it to the owner of the neighboring property, the neighbor can generally have the sale annulled so that he can purchase the property. This provision does not apply in the following cases:
1) the buyer did not have any other home in which to live;
2) the seller was in immediate need for money and the buyer was able to pay in full up front;
3) the neighbor wishes to purchase the house for somebody else;
4) the buyer purchased the house for a Mitzva, such as to be used as a synagogue.
If the neighbor rents the facility, and does not own it, it is unclear whether or not he enjoys the right of first of refusal; in such a case one must consult a competent Halachic authority for guidance.
See the book- "Pure Money" by Dayan Cohen, pages 179-181.