First, as a practical matter, X should determine to what extent he or she cares about what sounds like a few inches of property if X plans to live at this location and, thus, have Y as a neighbor for however many years. That said, if neighborly relations are of no or minimal concern, X should probably a) pursue available avenues through title insurance, b) consider a lawsuit to quiet title, and/or c) go along with building his fence as he pleases. While a) should be rather obvious and b) could be worth its own question (although you can read about it here), I'll focus on c).
First, Y can't just "claim to have adverse possession" and refuse to move something. The landowner claiming adverse possession must actually file suit and prove the elements of the claim.
To prove the claim, the party seeking adverse possession must use the other party's land in a manner which is Open, Continuous, Exclusive, Adverse/Hostile, and Notorious. Generally, this means the party seeking adverse possession must have been actually using/accessing that property, that the use must not have been in secret or hidden, that such use has been "broadcast" to the public and "received" by the true owner, that the use was wrongful and, therefore provided a cause of action for the true owner, that the land was not shared with the actual owner during that time, and continuous for 20 years. The link above goes into some good detail about each of these should you be interested.
How to Prevent:
Most importantly, land registered with the Land Court cannot be adversely possessed. I believe this is rather unique to Massachusetts.
More generally,
- Posting “No trespassing” signs (can be helpful, but is not fail-safe)
- Physically demarcate lot lines with a fence, gate or the like (survey stakes alone may not be enough)
- Document giving permission to an encroaching neighbor by written document or agreement
- For prescriptive easements, record a statutory Notice to Prevent Acquisition of Easement. Note: this notice will not prevent a claim of
adverse possession to the entire land.