You have even more fine options than 2.
However the amount of years is the key decision criteria.
If it is the short list of years (maybe up to 10) the selection dropdown list is the best. People became used to that with expiration dates on credit cards.
For the long list the masked input is fine.
Additionally you can provide the slider. Beware that some users expect to enter the editing mode here by clicking / tapping on year. There you would enter the masked input.
If you want to be more strict you could use the spins on particular ciphers of a year number. People know this pattern from locks. By that you can impose better limits or even fix some parts (e.g. 2 0 ... while allowing to select within the rest).
What you use also depends on how many other inputs you have on the screen and on the importance of this particular input.
Anyway the fine UX implementation executes immediate validation checks (e.g. min/max) and provides the feedback to user.